synchronization
15 tutorials tagged “synchronization”.
- Deadlock in JavaA deadlock is when threads wait forever for locks held by each other. Learn its four conditions, how to spot one with jstack, and how lock ordering prevents it.
- Inter-Thread Communication in Javawait(), notify() and notifyAll() let threads signal each other through an object's monitor. Learn the rules, the while-loop pattern, and a ready-signal example.
- Java Memory Model and Happens-BeforeThe Java Memory Model defines when one thread's writes become visible to another. Learn reordering, the happens-before rules, and how to apply them correctly.
- Livelock and Starvation in JavaLivelock is threads busily reacting to each other without progress; starvation is a thread that never gets a turn. Learn both, with examples and fixes.
- Object Lock vs Class Lock in JavaAn object lock belongs to one instance and guards its data; a class lock belongs to the Class object and guards static data. Compare them with an example.
- Producer-Consumer Problem in JavaProducers add items to a bounded buffer and consumers remove them. Solve the producer-consumer problem with wait/notifyAll, then with BlockingQueue.
- Race Conditions and Thread SafetyA race condition happens when the result depends on thread timing. Learn the read-modify-write and check-then-act races, and the ways to make code thread-safe.
- Reentrant Monitor in JavaJava's intrinsic locks are reentrant: a thread that holds a lock can enter other code synchronized on the same lock. Learn why this matters, with examples.
- Difference Between Thread.sleep() and Object.wait()sleep() pauses a thread for a time and keeps its locks; wait() releases the lock and waits for a signal. Learn every difference with an example.
- Static Synchronization in JavaStatic synchronized methods lock the Class object, protecting static fields shared by all instances. Learn the syntax, when it is needed, and a common mistake.