慕课网多线程教程
ArrayList
HashMap
/**
* 描述: 演示Vector,主要是看Vector源码
*/
public class VectorDemo {
public static void main(String[] args) {
Vector<String> vector = new Vector<>();
vector.add("test");
System.out.println(vector.get(0));
}
}
synchronized
修饰,可以保证线程安全,但性能受影响/**
* 描述: TODO
*/
public class HashtableDemo {
public static void main(String[] args) {
Hashtable<String, String> hashtable = new Hashtable<>();
hashtable.put("学完以后跳槽涨薪幅度", "80%");
System.out.println(hashtable.get("学完以后跳槽涨薪幅度"));
}
}
/**
* 描述: 演示Collections.synchronizedList(new ArrayList())
*/
public class SynList {
public static void main(String[] args) {
List<Integer> list = Collections.synchronizedList(new ArrayList<Integer>());
list.add(5);
System.out.println(list.get(0));
Map<Object, Object> objectObjectMap = Collections.synchronizedMap(new HashMap<>());
}
}
CopyOnWriteArrayList
使用于读多写少的情况