From 95c439a1141df334525147bfcc67841ab183f9ee Mon Sep 17 00:00:00 2001 From: chenlw <874313221@qq.com> Date: Wed, 28 Dec 2016 11:20:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/com/platform/test/MapTest.java | 23 ++++++++++++++++++----- test/com/platform/test/MyTestThread.java | 9 ++------- test/com/platform/test/testThread.java | 21 +++++++++++++++++++-- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/test/com/platform/test/MapTest.java b/test/com/platform/test/MapTest.java index 97d929ff..0ef0c3af 100644 --- a/test/com/platform/test/MapTest.java +++ b/test/com/platform/test/MapTest.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import org.junit.Test; @@ -81,12 +82,24 @@ public class MapTest { @Test public void test2() { - Map map = new HashMap(); - map.put("12", "0"); - if ("0".equals(map.get("12"))) { - System.out.println("-----"); + Map map = new HashMap(); + CheckoutEntity t = new CheckoutEntity(); + t.setId(21); + map.put("12", t); + map.put("13", t); + map.put("14", t); + Set keys = map.keySet(); + String tmpKey = ""; + if (keys.size() > 0) { + tmpKey = keys.iterator().next(); + System.out.println(tmpKey); + } + CheckoutEntity data = map.get(tmpKey); + map.remove(tmpKey); + if (null != data) { + + System.err.println(data.getId()); } - } } diff --git a/test/com/platform/test/MyTestThread.java b/test/com/platform/test/MyTestThread.java index 82e240c4..3e9372f1 100644 --- a/test/com/platform/test/MyTestThread.java +++ b/test/com/platform/test/MyTestThread.java @@ -1,18 +1,13 @@ package com.platform.test; -public class MyTestThread extends Thread{ +public class MyTestThread implements Runnable{ - public MyTestThread() { - this.setDaemon(true); - } - @Override public void run() { for (int i = 0; i < 1000; i++) { - System.out.println(i); try { - Thread.sleep(5); + Thread.sleep(50); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); diff --git a/test/com/platform/test/testThread.java b/test/com/platform/test/testThread.java index 28322553..bdd14624 100644 --- a/test/com/platform/test/testThread.java +++ b/test/com/platform/test/testThread.java @@ -1,12 +1,29 @@ package com.platform.test; +import com.platform.utils.ThreadVolume; + public class testThread { public static void main(String[] args) { MyTestThread thj = new MyTestThread(); - thj.start(); - System.err.println(thj.isDaemon()); + Thread th = new Thread(thj,"test1"); + th.setDaemon(true); + th.start(); + System.err.println(th.isDaemon()); + ThreadGroup group = Thread.currentThread().getThreadGroup(); + System.err.println(group.getName()); + int size = group.activeCount(); + Thread[] slackList = new Thread[size]; + + /* 获取根线程组的所有线程 */ + int actualSize = group.enumerate( slackList ); + + Thread[] list = new Thread[actualSize]; + System.arraycopy( slackList, 0, list, 0, actualSize ); + for (Thread thread : list) { + System.err.println(thread.getName()); + } } }