Table of Contents

About

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.

Idioms

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

Method

Statement

Implementation

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