How is the synchronized java keyword implemented?

In C #, the lock keyword is good syntax for a try/catch and an instance of Monitor .

In Java, which synchronization class is used by the synchronized keyword hood user?

Edit - I made another conclusion - it looks like it is synchronized, compiled for ontecode monitorenter / monitorexit operations. Is there a class that duplicates this semantics?

+6
source share
2 answers

No class is used - this is a JVM-driven language construct.

However, Java 5 introduced java.util.concurrent.locks , where you have Lock and its many implementations. See Related Documents for sample use.

+4
source

The synchronized causes the entity it modifies to synchronize with the internal JVM lock. There is no architectural class for this as far as I can recall, and this does not necessarily correspond to any particular OS design.

However, there is a bytecode mechanism for the lock mechanism used to enter / exit synchronized blocks {} .

+2
source

Source: https://habr.com/ru/post/895078/


All Articles