isInterrupted和interrupted的区别:1.后者是静态方法,前者不是; 2.前者只反映线程是否被中断,而不改变线程的状态;后者不仅反映线程是否被中断,在线程为中断状态时调用此方法还会清除线程的中断状态。
以下是具体说明和测试:
1.isInterrupted
Java中isInterrupted()方法的注释如下:
public boolean isInterrupted()
Tests whether this thread has been interrupted. The interrupted status of the thread is unaffected by this method.
A thread interruption ignored because a thread was not alive at the time of the interrupt will be reflected by this method returning false.
Returns:true if this thread has been interrupted; false otherwise.
注释中说到:测试该线程是否已被中断。线程的中断状态不受此方法的影响。线程中断被忽略,因为在中断时线程不是活动的,这将通过返回false的方法反映出来。
下面具体测试一下:
public static void main(String[