Java Concurrency - Synchronization (Thread Safety)

1 - 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.

3 - Idioms

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

3.1 - Method

3.2 - Statement

4 - 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.

5 - Documentation / Reference

Data Science
Data Analysis
Data Science
Linear Algebra Mathematics

Powered by ComboStrap