This repository is a comprehensive study and implementation of core and advanced concurrent programming design patterns in Java. It explores how to identify, triage, and solve multithreading hazards.
- Race Conditions: Corrupted shared memory due to unsynchronized read-modify-write CPU instructions (see
Counter.java). - Deadlocks: The Coffman Conditions and circular wait states, addressed via strict Lock Ordering techniques (see
BankTransfer.java). - Starvation: Addressed through fairness flags and ReentrantLocks.
- Producer-Consumer: Utilizing
wait()andnotifyAll()within while-loops to safely coordinate thread hand-offs. - Readers-Writers: Balancing massive parallel read throughput while enforcing mutually exclusive write privileges.
- Dining Philosophers: Resolving complex circular-wait bottlenecks utilizing Global Lock Ordering and central "Waiter" arbitration strategies.
- Custom Thread Pools: Demonstrating
ExecutorServiceinternals by managing shared task queues and continuous worker loops. - Connection Pools: utilizing
Semaphorelogic to accurately constrain and marshal access to expensive shared resources without explicitsynchronizedlocks. - Rate Limiters: Highly scalable, lock-fragmented architectures for bounding API traffic. Includes
FixedWindowandTokenBucketalgorithm implementations with specializedConcurrentHashMaphandling.
A detailed master guide covering all underlying theory, memory models, JVM locking optimizations, and concurrency principles can be found in Learnings.md.