Actual use of lockInterruptibly for a ReentrantLock

Rollerball picture Rollerball · Jul 23, 2013 · Viewed 12.9k times · Source

What do you actually use for this method lockInterruptibly? I have read the API however it's not very clear to me. Could anybody express it in other words?

Answer

Evgeniy Dorofeev picture Evgeniy Dorofeev · Jul 23, 2013

lockInterruptibly() may block if the the lock is already held by another thread and will wait until the lock is aquired. This is the same as with regular lock(). But if another thread interrupts the waiting thread lockInterruptibly() will throw InterruptedException.