Locksmedium3-5 years
Why would you choose ReentrantLock over synchronized?
For tryLock (non-blocking or with a timeout), lockInterruptibly, fairness, multiple Conditions per lock, introspection, and because virtual threads unmount while blocked on it (before Java 24 they pin on synchronized). The cost: you must unlock() in finally, every time.
PreviousWhen would you use synchronized, and when volatile?Next Explain ThreadPoolExecutor's parameters and how a task moves through them.