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