Synchronized
In Java, synchronized is a language construct that acquires an object's monitor to provide mutually exclusive access to a method or block of code.
Troubleshooting Java, Second Edition
A synchronized block is a Java language construct that acquires an object's monitor while executing a guarded section of code.
- How it is used
- Protects shared-resource updates in multithreaded producer-consumer applications and supports investigation of concurrency behavior.
- How deep it goes
- Explains monitor exclusivity, waiting, profiling symptoms, and nested-block deadlocks, while deferring detailed thread-dump reading.
- Examples
- Uses producer and consumer threads modifying an ArrayList, VisualVM timelines, and oppositely ordered listA and listB monitors.
- What you can do after
- Diagnoses lock-related slowdowns with profilers and recognizes deadlock-prone nested synchronized blocks.
Read how Troubleshooting Java, Second Edition explains synchronized →
Troubleshooting Java: Read, debug, and optimize JVM applications
A Java language construct that restricts execution of a code block so that only one thread at a time can hold its associated monitor.
- How it is used
- Protects shared-resource access from concurrent changes and provides a focus for investigating lock-related performance problems.
- How deep it goes
- Works through shared-list locking and reversed nested-monitor deadlock, then outlines profiling without detailing JVM lock internals.
- Examples
- Shows producers and consumers synchronizing on a shared list, plus two threads acquiring list monitors in opposite orders.
- What you can do after
- Diagnose lock-related slowdowns by sampling first, then using lock profiling to inspect affected threads, monitors, and lock relationships.
Read how Troubleshooting Java: Read, debug, and optimize JVM applications explains synchronized →
What to know first
- threadA thread is a distinct sequence of execution with its own control flow and state, managed or scheduled by a processor, runtime, or operating system.
- monitorA monitor is an object-associated synchronization mechanism that provides mutual exclusion and coordinates thread waiting and notification.
- instrumentationInstrumentation is the addition or configuration of mechanisms in software or systems to observe, measure, or record execution and behavior.
- multithreadingMultithreading is the execution of multiple threads of control within a program, concurrently through interleaving or simultaneously.
Related concepts
- monitoruses · A monitor is an object-associated synchronization mechanism that provides mutual exclusion and coordinates thread waiting and notification.
- lockingproduces · Locking is a synchronization technique that controls concurrent access to a shared resource or protected operation.
- race conditionaddresses · A race condition is a concurrency defect in which program behavior or results depend on the timing or ordering of interacting operations.
Questions about synchronized
What is synchronized?
In Java, synchronized is a language construct that acquires an object's monitor to provide mutually exclusive access to a method or block of code.
Which Manning books explain synchronized?
Troubleshooting Java, Second Edition and Troubleshooting Java: Read, debug, and optimize JVM applications.
What should I know before learning synchronized?
Manning books that teach synchronized usually introduce thread, monitor, instrumentation and multithreading first.
What is the difference between synchronized and volatile variable?
In Java, synchronized is a language construct that acquires an object's monitor to provide mutually exclusive access to a method or block of code. A volatile variable is a shared variable whose accesses provide defined cross-thread visibility and memory-ordering semantics.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

