Why can't Thread.interrupt () interrupt a thread trying to get a lock

The Thinking in Java book says that Thread.interrupt() cannot interrupt a thread that is trying to get a synchronized lock, I want to know why?

+5
source share
2 answers

A blocking operation can only be interrupted if a throw InterruptedException declared. It is clear that the synchronized block does not announce this, so it is not possible to interrupt a thread while it is waiting for a lock.

Alternatively, you can use explicit locking and calling Lock.lockInterruptibly() .

+6
source

A book is incorrect if it only refers to the synchronized . Object.wait() throws InterruptedException .

+1
source

All Articles