码迷,mamicode.com
首页 > 编程语言 > 详细

java interrupted与isInterrupted方法

时间:2017-12-17 17:02:50      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:java interrupted

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 interrupted

原文地址:http://blog.51cto.com/2839840/2051509

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