Is a Java lockout object enforcing an earlier relationship?

Java provides the Lock object in the concurrency package, which according to the documentation provides more extensive locking operations than can be obtained using synchronized methods and statements.

Synchronized methods / blocks, in addition to mutual exclusion, provide a link between events and previous ones, which makes it possible for changes made to a variable by one thread to be visible to another.

Is there a relationship when using a Lock object? Is surveillance guaranteed like in the case of a synchronized block for all platforms?

+6
source share
2 answers

Is there a relationship when using a Lock object? Observation as in the case of a synchronized block for all platforms?

Yes it is.

There are several actions that create: in front of a relationship, and one of them is synchronization ( here ), and the Java lock object is also designed for this purpose.

Read about Java Memory Alignment Properties from Oracle Docs. Except below to be highlighted in the link.

The “Extending these safeguards” section below refers to memory consistency properties, such as the “occur before” relationship. Lock class belongs to the java.util.concurrent , so it guarantees memory consistency properties, such as the "happen sooner" relationship, etc.

The methods of all classes in java.util.concurrent and its subpackages extend these guarantees for higher-level synchronization.

+1
source

Yes it is.

Lock objects are very similar to the implicit locks used by synchronized code. As with implicit locks, only one thread can Block an object at a time . Lock objects also support the wait / notify mechanism through related state objects.

From https://docs.oracle.com/javase/tutorial/essential/concurrency/newlocks.html

+2
source

All Articles