user1730789
user1730789

Reputation: 5177

Java Synchronization and Re-Entrant locking

when we Synchronize on an object, is this a Re-Entrant lock? Is there a real difference between between a Synchronization lock and a Re-Entrant lock ?

Kind Regards,

Upvotes: 1

Views: 214

Answers (1)

Enno Shioji
Enno Shioji

Reputation: 26882

Yes, lock by synchronized keyword is re-entrant. The implementation can be different between them though. For example, in earlier versions of JVM, the ReentrantLock's implementation had much better through-put than synchronized keyword had. If or how the implementation differs is dependent on the JVM implementation/version.

In general, I tend to recommend to use the synchronized keyword if you don't require additional features the class ReentrantLock provides. But this is ultimately a preference.

Upvotes: 2

Related Questions