Java
234 notes
Some notes are currently available only in Chinese. English translations are shown when available.
- 6.21 Kernel-Level Threadhistorical
1. What it is. 2. How to verify that Java threads are kernel-level threads. 2.1. Before running. 2.2. After running.
- 6.22 Unsafehistorical
What Unsafe is, how it relates to manual memory access, and examples of reading and atomically updating fields by memory offset.
- 6.23 Revisiting the JMMhistorical
After understanding the underlying computer architecture, revisit why the Java Memory Model is needed, what it defines, and happens-before.
- 6.24 Lock Optimizationhistorical
1. JVM optimizations for locks: lock elimination, lock coarsening, biased locking, and adaptive locking. 2. Analysis of lock inflation. 3. Application-level optimization of lock usage. 4. Adjusting the number of spins.
- 6.25 Implementing a Simple AQS by Handhistorical
Build a simple AQS-like lock by hand to better understand the real AQS source code: requirements, fields, blocking/waking, waiter queue, lock/unlock flow, fairness, final implementation, test, and flow.
- 6.26 Fair Lockhistorical
A fair lock follows the first-come, first-served principle. Even after the lock has been released, a later-arriving thread cannot barge in; it must wait until nobody is ahead of it. 1. Usage. 2. Principle analysis.
- 6.27 BlockingQueuehistorical
1. What it is. A thread-safe blocking queue. Characteristics: FIFO; blocking insertion when the queue is full and blocking removal when the queue is empty; bounded or unbounded capacity; thread safety. 2. Use cases. Producer-consumer. 3. How to use it. 4. Detailed comparison of BlockingQueue implementations.
- 6.28 Executorshistorical
1. Usage 2. newCachedThreadPool 3. newScheduledThreadPool 4. newFixedThreadPool 5. newSingleThreadExecutor
- 6.29 ConcurrentHashMap in JDK 1.8historical
1. What it is. A thread-safe HashMap implemented with synchronized + CAS + the HashMap structure (array + linked list + red-black tree). 2. How to use it. 3. Principle analysis: constructor, Node, put, initialization, insertion, resizing, get, remove, and containsKey.
- 6.30 Producer-Consumerhistorical
1. Using BlockingQueue. 2. Using wait/notify. 3. Using Lock/Condition. Compared with wait/notify, two Conditions are used so producers and consumers are not woken together; each side wakes only the other side.