并發(fā)
線程
Thread Runnable
中斷線程
- interrupt
- 調(diào)用該方法,線程的中斷狀態(tài)將被設(shè)置為true
- 被中斷的線程調(diào)用isInterrupted判斷是否被請求中斷
- 如果被請求的線程被阻塞,將會拋出InterruptedException,而且線程的中斷狀態(tài)將會被清除
- interrupted
靜態(tài)方法,調(diào)用該方法將檢測當(dāng)前線程是否被中斷,并清除中斷狀態(tài)
- isInterrupted
實(shí)例方法
- InterruptedException
線程狀態(tài)
- NEW
- Runnable
- Blocked
- Waiting
- Timed waiting
- Terminated
狀態(tài)之間的轉(zhuǎn)換圖
線程屬性
- 優(yōu)先級
- 守護(hù)線程
- 未捕獲異常處理
同步
- 競爭條件
- 鎖對象
synchronized ReentrantLock
- 條件對象
Condition await SignalAll
- synchronized關(guān)鍵字
- 同步阻塞
- 監(jiān)視器概念
- volatile域
- final變量
- 原子性
- 死鎖
- 線程局部變量
- 鎖測試與超時
- 讀寫鎖
- 為什么棄用stop和suspend
阻塞隊(duì)列
BlockingQueue ArrayBlockingQueue LinkedBlockingQueue DelayQueue Delayed PriorityBlockingQueue BlockingDeque TransferQueue
線程安全的集合
- 高效的映射, 集合隊(duì)列
ConcurrentHashMap ConcurrentSkipListMap ConcurrentLinkedQueue
- 映射條目的原子更新
- replace
- putIfAbsent increment
- compute computeIfAbsent merge computeIfPresent
- 對并發(fā)散列映射的批操作
- 搜索: searchKeys searchValues search searchEntries
- 規(guī)約: reduceKyes reduceValues reduce reduceEntries
- forEach:
- 并發(fā)集視圖
- ConcurrentHashMap.newKeySet
- map.keySet(1L)
- 寫數(shù)組拷貝
- CopyOnWriteArrayList
- CopyOnWriteArraySet
- 并行數(shù)組算法
Arrays類提供了大量并行化操作
- 較早的線程安全集合
Callable與Future
- Callable
- Future
- FutureTask
執(zhí)行器
Executor
- 線程池
- newCachedThreadPool
- newFixedThreadPool
- newSingleTreadExecutor
- ExecutorService
- 預(yù)定執(zhí)行
- ScheduledExecutorService
- newScheduledThreadPool
- newSingleThreadScheduledExecutor
- 控制任務(wù)組
- shutdownNow
- invokeAny
- invokeAll
- ExecutorCompletionService
- Fork-join框架
- 可完成Future
- CompletableFuture
同步器
- 信號量Semaphore
- 倒計(jì)時門栓 CountDownLatch
- 障柵 CyclicBarrier
- 交換器 Exchanger
- 同步隊(duì)列 SynchronousQueue