Java
234 notes
Some notes are currently available only in Chinese. English translations are shown when available.
- 6.11 11.CopyOnWriteArraySethistorical
1. What it is. A copy-on-write set: ordered and without duplicates, implemented internally with CopyOnWriteArrayList. 2. How to use it. 3. Principle analysis. 3.1. Constructor. 3.1.1. The underlying implementation uses CopyOnWriteArrayList. 3.2. add method. 3.2.1. Delegates to CopyOnWriteArrayList.
- 6.12 ArrayBlockingQueuehistorical
What ArrayBlockingQueue is, how to use it, and source analysis of its array, lock, conditions, put/take/offer/poll/add/remove/element/peek methods.
- 6.13 13.ThreadLocalhistorical
What ThreadLocal is, how to use it, and source analysis of ThreadLocalMap, set/get/remove, open addressing, weak keys, and memory-leak concerns.
- 6.14 14.ThreadPoolhistorical
1. What it is. Java's thread-pool framework separates task submission from task execution. 1.1. Why thread pools are needed: reuse threads, because creating/destroying threads is expensive and too many threads cause excessive CPU context switching. 1.2. Use cases: individual tasks should not run too long, and there are many tasks.
- 6.15 CompletableFuturehistorical
1. What it is. Used for asynchronous programming. In Java, so-called asynchronous programming means putting blocking code into a separate thread for execution and notifying the main thread when a result is available. 2. Future vs CompletableFuture. 3. Usage. 4. Source-code analysis.
- 6.16 ConcurrentHashMap in JDK 1.7historical
1. Constructor 2. put method 2.1. hash 2.2. ensureSegment 2.3. Segment.put 2.3.1. scanAndLockForPut 2.3.2. rehash 3. get 4. containsKey 5. remove 5.1. segmentForHash 5.2. Segment.remove
- 6.18 Exchangerhistorical
1. What it is. Used for exchanging data between two threads; data flows in both directions. 1.1. Exchanger vs. SynchronousQueue. 2. Usage. 3. Implementation analysis.
- 6.19 ReentrantReadWriteLockhistorical
1. What ReentrantReadWriteLock is. 2. ReentrantReadWriteLock categories. 3. References.
- 6.20 Semaphorehistorical
1. What it is. A rate-limiting utility class that allows only n threads to access a resource at the same time. 2. Implementation analysis. 2.1. UML.