java interrupted与isInterrupted方法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java interrupted与isInterrupted方法相关的知识,希望对你有一定的参考价值。

interrupted:测试当前线程是否是中断状态,执行完清除中断状态

isInterrupted:测试Thread对象是否是中断状态,不清除中断状态

public static boolean interrupted() {
        return currentThread().isInterrupted(true);
    }

    /**
     * Tests whether this thread has been interrupted.  The <i>interrupted
     * status</i> of the thread is unaffected by this method.
     *
     * <p>A thread interruption ignored because a thread was not alive
     * at the time of the interrupt will be reflected by this method
     * returning false.
     *
     * @return  <code>true</code> if this thread has been interrupted;
     *          <code>false</code> otherwise.
     * @see     #interrupted()
     * @revised 6.0
     */
    public boolean isInterrupted() {
        return isInterrupted(false);
    }

    /**
     * Tests if some Thread has been interrupted.  The interrupted state
     * is reset or not based on the value of ClearInterrupted that is
     * passed.
     */
    private native boolean isInterrupted(boolean ClearInterrupted);

以上是关于java interrupted与isInterrupted方法的主要内容,如果未能解决你的问题,请参考以下文章

Java并发编程-如何终止线程

java多线程 interrupt(), interrupted(), isInterrupted()方法区别

关于Java多线程-interrupt()interrupted()isInterrupted()解释

java 多线程5: java 终止线程及中断机制 (stop()interrupt() interrupted()isInterrupted())

关于线程 interrupt

Java 多线程基础interrupt()和线程终止方式