问题
In this code
public class NoncancelableTask {
public Task getNextTask(BlockingQueue<Task> queue) {
boolean interrupted = false;
try {
while (true) {
try {
return queue.take();
} catch (InterruptedException e) {
interrupted = true;
// fall through and retry
}
}
} finally {
if (interrupted)
Thread.currentThread().interrupt();
}
}
interface Task {
}
}
I understand that setting the interrupted status lets the caller of this method retain the status of interruption to do something with it according to the methods policy.
However Goetz also says that this method is used for "activities that do not support cancellation"
So my question is whats even the point of doing that if its never even going to go into the finally block and back up the call stack to its caller?
来源:https://stackoverflow.com/questions/48088316/what-is-the-point-of-restoring-the-interrupted-status-in-jcip-listing-7-7