Q48: How does ReentrantLock differ from the synchronized keyword?

FeaturesynchronizedReentrantLock
Lock MechanismImplicit JVM MonitorExplicit Java object API
FairnessUnfair lock acquisitionSupports Fair / Unfair lock configurations
InterruptibilityCannot interrupt waiting threadSupports lockInterruptibly()
Timed AcquisitionNot supportedSupports tryLock(timeout, unit)
Condition SupportSingle wait-set (wait/notify)Multiple condition variables (newCondition())
Key Takeaways
  • ReentrantLock provides advanced features (tryLock, fairness policies, multiple conditions).
Knowledge Check

Which feature is unique to ReentrantLock compared to synchronized blocks?