isInterrupted方法 主线程输出当前两个线程的状态,输出true/false一直会在变化

package one;

import java.util.Date;
import java.util.*;

public class TestInterrupt {

public static void main(String[] args) {
    Thread1 thread = new Thread1();
    thread.start();
    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {

    }
    thread.interrupt();

    System.out.println(thread.isInterrupted());
    System.out.println(Thread.interrupted());
    System.out.println(thread.isInterrupted());
}

}
class Thread1 extends Thread {
public void run(){
while(!isInterrupted()){
System.out.println(new Date()+" "+isInterrupted());
try {
sleep(1000);
} catch (InterruptedException e) {
return ;
}finally{
//System.out.println(isInterrupted());
}
}
}

}
![图片说明](https://img-ask.csdn.net/upload/201607/12/1468254243_846472.png)图片说明

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问