package thread1;
public class TestInterrupted {
public static void main(String[] args) {
a aa = new a();
Thread t = new Thread(aa);
t.start();
// 中断t线程
t.interrupt();
// 中断当前线程(main)
Thread.currentThread().interrupt();
// 测试线程是否中断
System.out.println(Thread.currentThread().isInterrupted());
System.out.println(Thread.currentThread().isInterrupted());
// interrupted是测试当前线程(main)是否中断,具有清除功能,所以第一次是true,第二就是false
System.out.println(Thread.currentThread().interrupted());
System.out.println(Thread.currentThread().interrupted());
}
}
class a implements Runnable {
public void run() {
for (int i = 0; i < 50; i++) {
System.out.println(i);
}
}
}