⚡ Advanced Concurrency
14 Java concepts, each explained step by step with real code, a common trap and practice questions.
- ExecutorService & thread poolsFixed, cached, scheduled pools; submit vs execute; shutdown.
- Callable & FutureReturning results, get() blocks, cancel, ExecutionException.
- CompletableFuturesupplyAsync, thenApply, thenCompose, thenCombine, allOf, exceptionally.
- Atomic classes & CASAtomicInteger, compare-and-set, LongAdder under contention.
- ReentrantLock & ConditiontryLock, fairness, lockInterruptibly, always unlock in finally.
- ReadWriteLock & StampedLockMany readers or one writer; optimistic reads.
- ConcurrentHashMapThread-safe map, atomic compute/merge, no null keys or values.
- Other concurrent collectionsCopyOnWriteArrayList, ConcurrentLinkedQueue, BlockingQueue producer-consumer.
- SynchronizersCountDownLatch, CyclicBarrier, Semaphore, Phaser.
- Fork/Join frameworkDivide and conquer with RecursiveTask and work stealing.
- Virtual threadsJava 21 lightweight threads for blocking I/O at massive scale; pinning; don't pool them.
- Structured concurrencyStructuredTaskScope (preview): treating related tasks as one unit.
- Scoped valuesJava 25 ScopedValue as an immutable, bounded alternative to ThreadLocal.
- Sizing thread poolsCPU-bound vs I/O-bound work, rejection policies, bounded queues.