Q48: How does ReentrantLock differ from the synchronized keyword?
| Feature | synchronized | ReentrantLock |
|---|---|---|
| Lock Mechanism | Implicit JVM Monitor | Explicit Java object API |
| Fairness | Unfair lock acquisition | Supports Fair / Unfair lock configurations |
| Interruptibility | Cannot interrupt waiting thread | Supports lockInterruptibly() |
| Timed Acquisition | Not supported | Supports tryLock(timeout, unit) |
| Condition Support | Single wait-set (wait/notify) | Multiple condition variables (newCondition()) |
Key Takeaways
ReentrantLockprovides advanced features (tryLock, fairness policies, multiple conditions).
Knowledge Check
Which feature is unique to ReentrantLock compared to synchronized blocks?