MultiThread/multithreading/src/main/java/thead/start/thread_8/Run.java

20 lines
714 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.start.thread_8;
public class Run {
public static void main(String[] args) {
try {
MyThread thread = new MyThread();
thread.start();
Thread.sleep(1000);
thread.interrupt();
// 输出false表示当前main从未中断过 interrupted 表示当前线程是否已经是中断状态执行后清除状态标志为false的功能
System.out.println("是否要停止1=" + Thread.interrupted());
System.out.println("是否要停止2=" + Thread.interrupted());
} catch (Exception exception) {
System.out.println("main catch");
exception.printStackTrace();
}
}
}