I have read http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html
I decide to make my lock uncancelable task by
try {
lockedRecords.wait();
} catch (InterruptedException e) {
interrupted = true;
}
but is there a need to
} finally {
if (interrupted) {
Thread.currentThread().interrupt();
}
}
The article says that you should call interrupt() to preserve the interrupted status. I’m still very blur, so what if I set .interrupt? what happens next? a bit lost on this.. any input?
What value does it bring to my program? Please kindly explain in layman terms, greatly appreciated 😀
What’s important here is the code that is not written in the example.
The method in the example (
getNextTask) could be used in:The
whileloop above executes forever, unless someone interrupts the thread on which this loop runs.If the interrupt status is not reset as is done in
getNextTaskhowever, when someone tries to interrupt the thread when the thread is inqueue.takeingetNextTask, then the interrupt is lost and the bit of code I wrote above will never stop looping.The whole point of the example on the IBM webpage is that you must be very careful when you swallow an interrupt since it might accidentally make a thread impossible to interrupt.