after catching “InterruptedException”, why “Thread.currentThread().isInterrupted()”'s value is false?

前端 未结 1 1822
长发绾君心
长发绾君心 2020-12-11 09:35

as the title.

public static void main(String[] args) throws InterruptedException {

    Thread thread = new Thread(new Runnable() {
        @Override
                


        
相关标签:
1条回答
  • From the Javadoc for Thread.sleep (called by TimeUnit.sleep):

    InterruptedException - if any thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.

    I think the intention of isInterrupted() is to allow you to detect whether a thread has been interrupted before calling something which would throw InterruptedException. If you've caught InterruptedException, it's fair to assume that the thread has been interrupted...

    0 讨论(0)
提交回复
热议问题