码迷,mamicode.com
首页 > 其他好文 > 详细

关于InterruptedException

时间:2020-07-10 17:17:49      阅读:75      评论:0      收藏:0      [点我收藏+]

标签: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();
    }

关于InterruptedException

标签:selection   immediate   live   throws   ble   cep   block   operation   lock   

原文地址:https://www.cnblogs.com/IC1101/p/13279994.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!