Why does Thread.isInterrupted () always return false?

后端 未结 4 1618
你的背包
你的背包 2020-11-27 17:47

I found the method of JavaDoc:

Returns: true if this thread has been interrupted; false otherwise.

I think something wrong with my understanding of

4条回答
  •  孤独总比滥情好
    2020-11-27 18:07

    You would check isInterrupted() in your own code, for example from a loop. If the thread has been interrupted you can then throw InterruptedException to stop executing.

    In your example if you caught InterruptedException you can be sure that it was interrupted and you don't have to check that method.

提交回复
热议问题