Concurrency

Threads and the state they share: Thread with a Runnable and the difference between start and run, a lost update measured on a real run and the synchronized that fixes it. ExecutorService pools the work, Callable and Future return a result and a failure, atomics count without a lock, and ReentrantLock locks and unlocks in a finally. The concurrent collections follow, with a producer and a consumer on a BlockingQueue, then CompletableFuture, and virtual threads, which run many tasks on the carriers. The capstone counts words in parallel and checks the total against one thread.

114 Threads Thread, Runnable, start against run, join, the main thread Open 115 Shared state and synchronized a lost update measured, synchronized, the same count after the fix Open 116 ExecutorService newFixedThreadPool, submit, invokeAll, shutdown, awaitTermination Open 117 Callable and Future a result from a task, get, a timeout, ExecutionException Open 118 Atomics AtomicInteger, incrementAndGet, compareAndSet, LongAdder Open 119 ReentrantLock lock and unlock, tryLock, Condition, the finally that unlocks Open 120 Concurrent collections ConcurrentHashMap, BlockingQueue, a producer and a consumer Open 121 CompletableFuture supplyAsync, thenApply, thenCombine, allOf, join Open 122 Virtual threads Thread.ofVirtual, newVirtualThreadPerTaskExecutor, a measured run of many tasks Open 123 Capstone: a parallel word count files, an executor, a ConcurrentHashMap, the result checked against one thread Open

Lessons