Question

I have strange issue with an await method of Condition class in Java SE 6. The problem is that await method NOT always throws an exception while interrupting by another thread.

In documentation it is written that the IE is thrown when:

... Some other thread interrupts the current thread, and interruption of thread suspension is supported ...

How to interpret this subsentense: "and interruption of thread suspension is supported"

It seams to be imposible to not throwing an exception. Do you ever had similar problem ?

Was it helpful?

Solution

Its not impossible not to throw InterruptedException what if the object has received signal via signal or signalAll API, the spec says these two methods will wake up any threads which are waiting on this condition.

OTHER TIPS

I had a similar issue, there was a thread waiting on a condition:

Lock someLock = new ReentrantLock();
Condition someCondition = someLock.newCondition();
...
someCondition.await(timeout, TimeUnit.MILLISECONDS);

and sending theThread.interrupt() did not work. It turned out that by mistake another thread was holding a someLock locked, so await() was blocked. After I added someLock.unlock() in proper place await() started throwing InterruptedException as expected.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top