What is the point of restoring the interrupted status in JCIP listing 7.7?

故事扮演 提交于 2019-12-11 15:57:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!