web_backend_develope
chenlw 8 years ago
parent 81308525b7
commit 95c439a114

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.junit.Test; import org.junit.Test;
@ -81,12 +82,24 @@ public class MapTest {
@Test @Test
public void test2() { public void test2() {
Map<String, String> map = new HashMap<String, String>(); Map<String, CheckoutEntity> map = new HashMap<String, CheckoutEntity>();
map.put("12", "0"); CheckoutEntity t = new CheckoutEntity();
if ("0".equals(map.get("12"))) { t.setId(21);
System.out.println("-----"); map.put("12", t);
map.put("13", t);
map.put("14", t);
Set<String> 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());
}
} }
} }

@ -1,18 +1,13 @@
package com.platform.test; package com.platform.test;
public class MyTestThread extends Thread{ public class MyTestThread implements Runnable{
public MyTestThread() {
this.setDaemon(true);
}
@Override @Override
public void run() { public void run() {
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
System.out.println(i);
try { try {
Thread.sleep(5); Thread.sleep(50);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();

@ -1,12 +1,29 @@
package com.platform.test; package com.platform.test;
import com.platform.utils.ThreadVolume;
public class testThread { public class testThread {
public static void main(String[] args) { public static void main(String[] args) {
MyTestThread thj = new MyTestThread(); MyTestThread thj = new MyTestThread();
thj.start(); Thread th = new Thread(thj,"test1");
System.err.println(thj.isDaemon()); 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());
}
} }
} }

Loading…
Cancel
Save