您的位置:首页 > 编程语言 > Java开发

java interrupted与isInterrupted方法

2017-12-17 16:16 267 查看
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