Part 9 5 chapters

Concurrency and Patterns in the Wild

Resource pools and virtual threads, shortcut patterns such as method-reference tables and dispatch maps, and anti-patterns to recognize and avoid.

Chapter 24

Virtual threads

What a virtual thread is, why fanning a shipment out to a hundred carrier rate APIs stops being expensive, and the concrete cases, CPU-bound work, pooling, pinning, ThreadLocal at scale, where a virtual thread is the wrong tool.

35 minRead โ†’
Chapter 25

Resource and concurrency patterns

Three idiomatic Java 25 shapes for bounding and serializing concurrent access, taught against a regional parcel-dispatch hub: a bounded connection pool with a blocking acquire, a monitor object that serializes a shared manifest, and an active object that decouples a call from the thread that runs it.

35 minRead โ†’
Chapter 26

Shortcut patterns: dispatch tables and maps

Two idiomatic Java 25 shortcuts for routing a key to a short handler without a full Strategy or Command hierarchy, taught against a shipping event feed: an EnumMap built from an exhaustive switch expression, and a Map dispatch table that registers a handler at runtime and falls back on an unrecognized key.

25 minRead โ†’
Chapter 27

Anti-patterns and pattern misuse

Recognizing patternitis in a shipping-rate pricing codebase: a singleton surcharge registry holding global mutable state, a factory-of-factories wrapped around an interface with one implementation, a god object that validates, logs, and formats, and a leaky abstraction that exposes its own call order. The simplified rewrite collapses six types into two records and one class that compute the same answer and are testable where the original was not.

30 minRead โ†’
Chapter 28

Patterns in a real framework: Quarkus and CDI

Quarkus's CDI container, Arc, answers the forces the hand-written patterns answer: constructor injection into a managed bean for Singleton and dependency injection, a producer method for Factory, an interceptor binding for Decorator and Proxy, a CDI event for Observer, and typed configuration for Strategy, in a shipping checkout service.

35 minRead โ†’