并发编程概述

并发编程

并发编程领域可以抽象成三个核心问题:分工、协作和互斥。

并发编程全景图

分工

  • ThreadPool/Executor
  • ForkJoinPool/ForkJoinTask
  • ScheduledThreadPoolExecutor
  • Guarded Suspension (wait/notify)
  • Balking pattern (reject)
  • Messaging design pattern

协作

  • Semaphore
  • monitor
    • Lock
      • ReadWriteLock
    • Condition
    • synchronized
  • CountDownLatch
  • CyclicBarrier
  • Phaser
  • Exchanger

互斥

无锁

  • local variables
  • immutable data structures
  • TLS
  • Copy-on-Write
  • CAS
  • atomic package

互斥锁

  • synchronized
  • Lock
  • ReadWriteLock