What is the difference between `ReentrantLock` and the `synchronized` keyword in Java?

Java Associate Hard

Java Associate — Hard

What is the difference between `ReentrantLock` and the `synchronized` keyword in Java?

Key points

  • ReentrantLock provides more functionalities than synchronized
  • synchronized is simpler but less flexible
  • ReentrantLock requires explicit unlock(), unlike synchronized
  • synchronized is a keyword, while ReentrantLock is a class
  • ReentrantLock allows for interruptible lock acquisition

Ready to go further?

Related questions