标签:util imp java err sleep static ati class pack
package cn.ruhsang.syn;
import java.util.ArrayList;
import java.util.List;
//线程不安全的集合
public class UnsafeList {
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
for (int i = 0; i < 10000 ; i++) {
new Thread(()->{
list.add(Thread.currentThread().getName());
}).start();
}
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(list.size());
}
}
标签:util imp java err sleep static ati class pack
原文地址:https://www.cnblogs.com/nigustudent/p/14860205.html