Java Concurrency - Synchronization (Thread Safety)

Java Conceptuel Diagram


Concurrency - Synchronization in java.

Java offers two basic synchronization idioms:

  • final fields, which cannot be modified after the object is constructed, can be safely read through non-synchronized methods, once the object is constructed.
  • Atomic Access does not require synchronization

The Java programming language neither prevents nor requires detection of deadlock conditions.


To create synchronized code (ie which gives consistent values) between threads, you use the synchronized word..




Synchronization is implemented by an internal entity known as the monitor (intrinsic lock or monitor lock).

  • Each object in Java is associated with a monitor, which a thread can lock or unlock.
  • Only one thread at a time may hold a lock on a monitor.
  • Any other threads attempting to lock that monitor are blocked until they can obtain a lock on that monitor.

Documentation / Reference

Discover More
Card Puncher Data Processing
Design pattern - The Singleton

The singleton pattern is a design pattern used to implement the mathematical concept of a singleton, by restricting the instantiation of a class to one object. This is useful when exactly one object is...
Java Conceptuel Diagram
Java - Concurrency (Parallel Work)

In concurrent or parallel programming, there are two basic units of execution: processes. A process is implemented as a main thread that can create other thread. and threads. Threads exist within...
Java Conceptuel Diagram
Java - Map

Map is a data structure implementation of the java collection framework. See java/util/MapMap hashmap. Permits null values and the null key. (The HashMap class is roughly equivalent to Hashtable,...
Java Conceptuel Diagram
Java - Static Modifier

in Java. The Java programming language supports static methods. Static methods, which have the static modifier in their declarations, should be invoked with the class name, without the need for...
Java Conceptuel Diagram
Java Concurrency - Atomic Variable Access

in java The reads and writes operations are atomic for reference variables for most primitive variables (all types except long and double). all variables declared volatile (including long...
Java Conceptuel Diagram
Java Concurrency - Fine-grained synchronization

Synchronized statements are also useful for improving concurrency with fine-grained synchronization. Suppose: class MsLunch has two instance fields, c1 and c2, c1 and c2 are never used together....
Java Conceptuel Diagram
Java Concurrency - Happens-before Relationship

in Java The following actions create happens-before relationships: synchronized construct. When a thread releases an intrinsic lock, a happens-before relationship is established between that action...
Java Conceptuel Diagram
Java Concurrency - Lock Objects (java.util.concurrent.locks)

java/util/concurrent/locks/package-summaryLock Object package is a High Level Concurrency of the java.util.concurrent. For low-level, intrinsic lock (monitor), see . There is interfaces and classes that...
Java Conceptuel Diagram
Java Concurrency - Monitor (Intrinsic|Implicit) Lock

Synchronization is built around an internal object property known as: intrinsic lock monitor lock implicit lock or simply monitor. Each object in Java is associated with a monitor, which a thread...
Java Conceptuel Diagram
Java Concurrency - Reentrant Lock

A thread cannot acquire a lock owned by another thread but a thread can acquire a lock that it already owns. Allowing a thread to acquire the same lock more than once enables reentrant synchronization....

Share this page:
Follow us:
Task Runner