1. List,Map,Set 线程安全性
2. 声明线程安全的集合方法
– 使用Collections. 方式构建
//make thread-safe list
List MyStrList = Collections.synchronizedList(new ArrayList());
MyStrList.add("123");
MyStrList.add("abc");
//make thread-safe hashset
Set set=Collections.synchronizedSet(new HashSet());
set.add(123);
set.add(456);
//make thread-safe hashmap
Map map=Collections.synchronizedMap(new HashMap());
map.put(1, "thb");
map.put(12, "bill tang");
– 使用ThreadLocal封装
参考文献
[1] List,Map,Set 线程安全性 - - ITeye博客
[2] java 中如何声明线程安全的集合 set, map 和 list大树叶新浪博客