6.JUC
Java · 43 notes
- 6.1 Hardware Foundations for Concurrencyhistorical
CPU caches, coherence, out-of-order execution, memory ordering, and why language memory models exist above hardware.
- 6.2 synchronizedhistorical
Java intrinsic monitors, mutual exclusion, happens-before visibility, reentrancy, synchronized methods/blocks, and JVM implementation caveats.
- 6.3 volatilehistorical
Java volatile visibility and ordering semantics, acquire/release-style happens-before behavior, atomic single reads/writes, and why volatile is not a lock.
- 6.4 Compare-and-Set (CAS)historical
Atomic compare-and-set as a read-modify-write primitive, retry loops, contention, ABA, and when lock-free does not mean contention-free.
- 6.5 AbstractQueuedSynchronizer (AQS)historical
AQS as the state-and-wait-queue framework behind many JUC synchronizers, with exclusive/shared acquisition, parking, cancellation, and template methods.
- 6.6 ReentrantLockhistorical
Explicit reentrant mutual exclusion with interruptible/timed acquisition, optional fairness, Conditions, and try/finally release.
- 6.7 Lock Conditionshistorical
Condition variables with await/signal, predicate loops, lock association, spurious wakeups, and the relationship to Object.wait/notify.
- 6.8 CyclicBarrierhistorical
A reusable barrier that releases a group when all parties arrive, with barrier actions, broken-barrier behavior, and comparison with CountDownLatch.
- 6.9 CountDownLatchhistorical
A one-shot shared countdown synchronizer for waiting until N events complete, with AQS shared-mode semantics.
- 6.10 CopyOnWriteArrayListhistorical
How CopyOnWriteArrayList provides lock-free reads by publishing immutable array snapshots, and when its write cost makes it unsuitable.
- 6.11 CopyOnWriteArraySethistorical
CopyOnWriteArraySet semantics, implementation relationship with CopyOnWriteArrayList, snapshot iteration, and read-heavy use cases.
- ArrayBlockingQueuehistorical
A fixed-capacity array-backed blocking queue with explicit backpressure, FIFO element order, and optional fairness.
- 6.13 ThreadLocalhistorical
Per-thread context storage, ThreadLocalMap lifetime, weak keys, stale values, thread-pool leaks, remove(), and modern context-propagation considerations.
- 6.14 ThreadPoolExecutorhistorical
Java thread-pool execution policy, core/max workers, work queues, rejection, shutdown, sizing, bounded backpressure, and modern virtual-thread context.
- 6.15 CompletableFuturehistorical
Composable asynchronous computation with CompletableFuture: stage chaining, error handling, executors, blocking hazards, and cancellation semantics.
- 6.16 ConcurrentHashMap in JDK 7historical
Historical JDK 7 ConcurrentHashMap design: segmented locking, read concurrency, and why these internals should not be generalized to modern JDKs.
- 6.17 Fork/Join Frameworkhistorical
Java ForkJoinPool, recursive task decomposition, work stealing, common-pool behavior, and the limits of fork/join for blocking work.
- 6.18 Exchangerhistorical
How Java Exchanger pairs two threads at a rendezvous point and atomically swaps one value from each participant.
- ReentrantReadWriteLockhistorical
A reentrant read/write lock with shared readers, exclusive writers, optional fairness, lock downgrading, and workload trade-offs.
- Semaphorehistorical
Permit-based concurrency control with acquire/release, bounded resource access, optional fairness, and the distinction from rate limiting.
- 6.21 User, Kernel, and Java Threadshistorical
User-level versus kernel-level threads, the traditional Java platform-thread mapping, and how virtual threads change the model.
- 6.22 Unsafehistorical
Why sun.misc.Unsafe exists, what low-level operations it exposes, and why supported Java APIs should usually be preferred.
- 6.23 The Java Memory Model (JMM)historical
Java's memory model, data races, happens-before, synchronization order, volatile, monitors, thread start/join, final fields, and sequential consistency for correctly synchronized programs.
- Optimizing Java Lockinghistorical
Durable lock-performance principles: reduce contention and critical sections, avoid blocking work while locked, split ownership carefully, and treat JVM lock internals as version-sensitive.
- Building an AQS-Style Synchronizerhistorical
A teaching implementation of a synchronizer using atomic state, a FIFO wait queue, park/unpark, and release wakeups, emphasizing invariants rather than copying JDK internals.
- Fair ReentrantLockhistorical
How fair ReentrantLock reduces barging by honoring queued predecessors, and the throughput/latency trade-off of fairness.
- BlockingQueuehistorical
Producer-consumer queues with bounded capacity, blocking/timed operations, backpressure, and the semantics of major Java BlockingQueue implementations.
- Executors Factory Methodshistorical
Convenience ExecutorService factories, their hidden queue/thread choices, and why explicit executor configuration or virtual-thread executors are often clearer.
- 6.16 ConcurrentHashMap in JDK 8historical
Historical JDK 8 ConcurrentHashMap design: CAS insertion, bin synchronization, tree bins, cooperative resizing, and stable public semantics.
- 6.30 Producer-Consumerhistorical
Producer-consumer coordination with BlockingQueue, wait/notify, and Condition, including bounded capacity and correct wait-loop semantics.
- Nonfair ReentrantReadWriteLockhistorical
Default read/write-lock acquisition, reader/writer barging policy, writer-starvation avoidance heuristics, and throughput trade-offs.
- Nonfair Semaphorehistorical
Default semaphore barging behavior, shared AQS permit state, and why nonfair acquisition often improves throughput.
- 6.33 Thread.sleephistorical
Thread.sleep timing semantics and the important difference between sleeping and waiting on an object monitor.
- Nonfair ReentrantLockhistorical
Default ReentrantLock barging behavior, why it can improve throughput, and how AQS queues still handle contended waiters.
- LinkedBlockingQueuehistorical
A linked-node blocking queue with optional capacity, separate producer/consumer coordination, and the risk of its very large default bound.
- RejectedExecutionHandlerhistorical
ThreadPoolExecutor overload policies as backpressure: abort, caller-runs, discard, discard-oldest, and custom rejection semantics.
- 6.37 Deadlock Examplehistorical
A minimal Java deadlock caused by inconsistent lock ordering, plus detection and prevention techniques.
- Fair ReentrantReadWriteLockhistorical
Fair read/write-lock scheduling, queued predecessors, reader grouping, writer progress, and fairness costs.
- Fair Semaphorehistorical
AQS shared acquisition with predecessor-aware fairness and the throughput trade-off of ordered permit allocation.
- 6.40 Java Thread Stateshistorical
The six Thread.State values, what each means, and why Java thread state is not identical to an operating-system scheduler state.
- PriorityBlockingQueuehistorical
An unbounded priority heap for concurrent producers/consumers, with ordering, capacity, and starvation caveats.
- SynchronousQueuehistorical
A zero-capacity rendezvous queue that directly hands an element from producer to consumer, with fair/nonfair transfer modes and thread-pool implications.
- Java Atomic Variableshistorical
AtomicInteger/Long/Reference, CAS-based read-modify-write, accumulators/adders, atomic references, memory semantics, and contention trade-offs.