Java Concurrency Interview

synchronized, monitors, wait and notify question 27 of 180 mid

What is reentrancy, and what would break without it?

A monitor records its owner and a hold count. The owning thread entering again just increments the count, and the monitor is released when the count reaches zero.

Without reentrancy, an ordinary pattern would hang: a synchronized method calling another synchronized method on the same object, or a synchronized equals on a subclass calling super.equals. Both synchronized and ReentrantLock are reentrant, which is what the name says. ReadWriteLock is the sharp edge here: a read lock cannot be upgraded to a write lock, and trying deadlocks the thread against itself.

synchronized locks

Quiz yourself on synchronized, monitors, wait and notify Suggest a correction