Tagged “Concurrency”
8 articles with this tag.
- Concurrency design patternsHow to introduce threads into an application: oneway messages, thread-per-message, worker threads and pools, completion callbacks, futures and joins, cooperative cancellation, push-flow pipelines, parallel decomposition with fork/join and barriers, and readers-writers — mapped from Doug Lea's patterns to modern Java 21 APIs.
- Designing concurrent objectsDoug Lea's design forces for concurrent Java — safety, liveness, performance and reusability — and the strategies for thread-safe objects: immutability, confinement, full synchronization, containment, lock splitting, optimistic updates with CAS, deadlock avoidance through lock ordering, and documenting thread-safety policies.
- SingletonEnsure a class has one instance and a global access point — and why that is harder, and more harmful, than it looks. Enum singletons, the holder idiom, double-checked locking with volatile, testability problems and the dependency-injection alternative, with a runnable Java 21 example.
- State-dependent actionsWhat a concurrent object should do when a request arrives in the wrong state: balk, wait (guarded suspension), wait with a timeout, or retry. wait/notify done correctly, Condition objects, a bounded buffer, interruption, the inheritance anomaly, and when to use BlockingQueue and other synchronizers instead.
- Concurrency APIPractical java.util.concurrent: threads vs tasks, ExecutorService and thread-pool sizing, Future and CompletableFuture composition and error handling, locks (synchronized, ReentrantLock, ReadWriteLock, StampedLock), atomics and LongAdder, synchronizers, concurrent collections and BlockingQueue, and how they relate to virtual threads.
- Java Memory ModelWhy concurrent Java code can see stale or reordered values: CPU caches and reordering, the Java Memory Model, happens-before rules, volatile, synchronized and final semantics, safe publication, double-checked locking, data races vs race conditions, and the JVM runtime memory areas (heap, stack, metaspace).
- Transactions and isolationWhat ACID really guarantees, and the concurrency anomalies each isolation level allows: dirty reads and writes, read skew, lost updates, write skew and phantoms. Read committed, snapshot isolation and MVCC, preventing lost updates, and the three ways to get serializability: serial execution, two-phase locking and serializable snapshot isolation.
- Virtual threadsJava's lightweight concurrency model: how virtual threads work (mounting, carriers, continuations), when they help, pinning and the Java 24 fix, using them in Spring Boot, structured concurrency for fan-out, scoped values vs ThreadLocal, and comparison with reactive programming.