1. 程式人生 > >java interrupted與isInterrupted方法

java interrupted與isInterrupted方法

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方法