Concurrency Patterns
Thread-Based Patterns
Reusable worker threads with task queue for bounded resource usage, avoiding thread creation overhead.
- Fixed, cached, scheduled pool types
- Work stealing algorithms
- Executor service abstraction
- Thread lifecycle management
- Web server request handling
- Background job processing
- Parallel data processing
- Batch operations
Decoupled producers and consumers sharing a queue with backpressure handling for load balancing.
- Blocking queue implementation
- Multiple producers/consumers
- Bounded buffer management
- Backpressure mechanisms
- Message processing systems
- Event handling pipelines
- Log processing
- Data transformation pipelines
Optimized locking allowing multiple concurrent readers OR single exclusive writer for shared resources.
- Read lock for concurrent access
- Write lock for exclusive access
- Starvation prevention
- Lock upgrade/downgrade
- Cache updates
- Configuration reading
- Database connection pools
- Shared state management
Synchronization point where threads wait for all to arrive before proceeding, supporting phased execution.
- Cyclic barrier for reuse
- Countdown latch for one-time
- Phaser for multiple phases
- Flexible participant count
- Parallel algorithm coordination
- Map-reduce operations
- Batch processing stages
- Simulation time steps
Message-Based Patterns
Isolated actors communicating via asynchronous messages with no shared state and location transparency.
- Private mailbox per actor
- Asynchronous message passing
- Supervision hierarchies
- Location transparency
- Akka framework (JVM)
- Erlang/Elixir processes
- Orleans virtual actors
- Distributed game servers
Placeholder for async computation results with composable operations, error handling, and cancellation support.
- Then/catch chaining
- Promise.all/race operations
- Cancellation tokens
- Timeout handling
- HTTP API calls
- Async file I/O
- Database queries
- Parallel async operations
Sequential processing stages with data transformation, parallel stage execution, and backpressure support.
- Stage isolation
- Backpressure handling
- Buffering between stages
- Error propagation
- Data processing pipelines
- Image processing
- ETL workflows
- Stream processing
