1,如果线程t通过Object的wait、或者线程的join 、sleep方法被阻塞, 那么当你(在当前线程中)对t发送t.interrupt 消息时, t的中断为被清除,同时t将收到 InterruptedException 异常。
2,如果t阻塞在的I/O操作中, 这时对t 发送中断消息会将t 的中断为置1, 并将收到 an 异常, 同时 io管道关闭。
3,如果线程t阻塞在 Selector 中, t收到中断消息后立马退出,不会收到异常。
public void interrupt ()
Added in
Posts an interrupt request to this Thread
. The behavior depends on the state of this Thread
:
Thread
s blocked in one ofObject
'swait()
methods or one ofThread
'sjoin()
orsleep()
methods will be woken up, their interrupt status will be cleared, and they receive an.
Thread
s blocked in an I/O operation of anwill have their interrupt status set and receive an
. Also, the channel will be closed.
Thread
s blocked in awill have their interrupt status set and return immediately. They don't receive an exception in this case.
See Also