标签:selection immediate live throws ble cep block operation lock
/**
* 中断当前线程;
*
* 如果这个线程被wait(), join(), sleep()所阻塞,
* 那么线程的中断状态将被清除,同时,会抛出一个InterruptedException;
*
* <p> If this thread is blocked in an invocation of the {@link
* Object#wait() wait()}, {@link Object#wait(long) wait(long)}, or {@link
* Object#wait(long, int) wait(long, int)} methods of the {@link Object}
* class, or of the {@link #join()}, {@link #join(long)}, {@link
* #join(long, int)}, {@link #sleep(long)}, or {@link #sleep(long, int)},
* methods of this class, then its interrupt status will be cleared and it
* will receive an {@link InterruptedException}.
*
* 如果这个线程是被I/O(基于InterruptibleChannel)操作所阻塞,
* 那么这个I/O通道教会被关闭,
* 线程interrupt状态会被设置为true,
* 同时会抛出一个ClosedByInterruptException;
*
* <p> If this thread is blocked in an I/O operation upon an {@link
* java.nio.channels.InterruptibleChannel InterruptibleChannel}
* then the channel will be closed, the thread‘s interrupt
* status will be set, and the thread will receive a {@link
* java.nio.channels.ClosedByInterruptException}.
*
* 如果这个线程是被link java.nio.channels.Selector所阻塞,
* 那么这个线程的interrupt状态会被设置为true,
* 并且会直接从selection操作中return,
* 就好像select.wakeup()一样;
*
* <p> If this thread is blocked in a {@link java.nio.channels.Selector}
* then the thread‘s interrupt status will be set and it will return
* immediately from the selection operation, possibly with a non-zero
* value, just as if the selector‘s {@link
* java.nio.channels.Selector#wakeup wakeup} method were invoked.
*
* 如果不存在前面所有情况,那么这个线程的interrupt状态将会被设置为true;
*
* <p> If none of the previous conditions hold then this thread‘s interrupt
* status will be set. </p>
*
* <p> Interrupting a thread that is not alive need not have any effect.
*
* @throws SecurityException
* if the current thread cannot modify this thread
*
* @revised 6.0
* @spec JSR-51
*/
//Thread.java
public void interrupt() {
if (this != Thread.currentThread())
checkAccess();
synchronized (blockerLock) {
Interruptible b = blocker;
if (b != null) {
interrupt0(); // Just to set the interrupt flag
b.interrupt(this);
return;
}
}
interrupt0();
}
标签:selection immediate live throws ble cep block operation lock
原文地址:https://www.cnblogs.com/IC1101/p/13279994.html