- AtomicInteger類(lèi):可以對(duì)基本數(shù)據(jù)/數(shù)組中的基本數(shù)據(jù)/類(lèi)中的基本數(shù)據(jù)進(jìn)行操作
- Executors類(lèi):
a. ExecutorService threadPool = Executors.newFixedThreadPool(3);固定大小線程池
b. ExecutorService threadPool = Executors.newCachedThreadPool();緩存線程池
c. ExecutorService threadPool = Executors.newSingleThreadExecutor();單一線程池 - Callable&Future:
a. Callable采用ExecutorService的submit方法提交,返回的future對(duì)象可以取消任務(wù)
b. Future取得的結(jié)果類(lèi)型和Callable返回的結(jié)果類(lèi)型必須一致,通過(guò)泛型來(lái)實(shí)現(xiàn)
Future<String> future = threadPool.submit(new Callable<String>() {
@Override
public String call() throws Exception {
Thread.sleep(2000);
return "hello";
}
});
CompletionService<Integer> completionService = new ExecutorCompletionService<~>(threadPool2);
for (int i = 0; i < 10; i++) {
final int seq = i;
completionService.submit(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
Thread.sleep(new Random().nextInt(5000));
return seq;
}
});
}
Lock&Condition
a. 兩個(gè)線程要實(shí)現(xiàn)互斥,它們必須用同一個(gè)Lock對(duì)象。
b. Lock與synchronize作用一樣,鎖本身是一個(gè)對(duì)象
c. 讀寫(xiě)鎖【多個(gè)讀鎖不互斥、讀鎖寫(xiě)鎖互斥、寫(xiě)鎖寫(xiě)鎖互斥】
d. Condition功能類(lèi)似Object的wait和notify方法
e. 一個(gè)鎖可以有多個(gè)Condition,即有多路等待和通知Semaphore信號(hào)燈
a. 可以維護(hù)當(dāng)前訪問(wèn)自身的線程個(gè)數(shù),并提供同步機(jī)制
b. 單個(gè)semaphore可以實(shí)現(xiàn)互斥鎖功能【一個(gè)線程獲得鎖,再由另一個(gè)線程釋放鎖】隊(duì)列BlockingQueue
a. 只有put方法和take方法才具有阻塞效果
b. 用兩個(gè)具有1個(gè)空間的隊(duì)列來(lái)實(shí)現(xiàn)同步通知功能
c. 與Semaphore相似;但隊(duì)列是一方存放數(shù)據(jù),一方釋放數(shù)據(jù);而Semaphore通常是由同一方設(shè)置和釋放信號(hào)量
d.ArrayBlockingQueue & LinkedBlockingDeque
同步集合【java5提供的】
a. ConcurrentHashMap
b. ConcurrentSkipListMap
c. ConcurrentSkipListSet
d. CopyOnWriteArrayList
e. CopyOnWriteArraySet使用了兩個(gè)condition?。?!

