Reputation: 2959
In C#, lock keyword is equivalent to Monitor.Enter() and Leave().
In Java, What is the equivalent one to synchronized keyword?
Upvotes: 1
Views: 62
Reputation: 262852
The synchronized
keyword makes use of JVM internals in its implementation. This is not exposed as a class.
There are additional (more powerful) synchronization primitives in the java.util.concurrent package. These do not use language keywords, but are used as classes, such as ReentrantLock. They in turn make use of sun.misc.Unsafe#park
, but you are not supposed to need to know about that.
Upvotes: 6