Are java Lock implementations using synchronized code?

Viewed 32

It's said that Lock is better than synchronized because of many reasons like ability to use different scopes, fairness etc. But as far as I'm concerned, synchronized is something that's implemented with native code, while ReentrantLock and others seem to be usual java classes.

I've been looking through ReentrantLock source code in particular and can't seem to find any synchronized block. Could someone please explain how is it possible to synchronize different threads without using synchronized blocks? There seems to be a lot of operations, none of which are atomic.

UPD: It's not exactly the same as the question about CPU usage, it's rather than which exact tool is used in Lock implementations to provide synchronization. I made some more research and it turns out that in the heart of ReentrantLock there's a native method that acquires the Lock. So that would be the answer to my question.

0 Answers
Related