MultiThread/multithreading/src/main/java/thead/thread_8/Run3.java

20 lines
694 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package thead.thread_8;
public class Run3 {
public static void main(String[] args) {
try {
MyThread thread = new MyThread();
thread.start();
Thread.sleep(1000);
thread.interrupt();
// 输出为true但是会有小概率会出现falseisInterrupted 所在的线程是否是中断状态,不清除状态标志
System.out.println("是否要停止1=" + thread.isInterrupted());
System.out.println("是否要停止2=" + thread.isInterrupted());
} catch (Exception exception) {
System.out.println("main catch");
exception.printStackTrace();
}
}
}