线程中断的作用是不是写反了
spiritn opened this issue · comments
1.4节:4.3.4线程中断
Thread.interrupt():中断线程。这里的中断线程并不会立即停止线程,而是设置线程的中断状态为true(默认是flase);
Thread.currentThread().isInterrupted():测试当前线程是否被中断。线程的中断状态受这个方法的影响,意思是调用一次使线程中断状态设置为true,连续调用两次会使得这个线程的中断状态重新转为false;
/**
* Tests whether this thread has been interrupted. The interrupted
* status of the thread is unaffected by this method.
*
*
A thread interruption ignored because a thread was not alive
* at the time of the interrupt will be reflected by this method
* returning false.
*/
public boolean isInterrupted() {
return isInterrupted(false);
}