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

20 lines
694 B
Java
Raw Normal View History

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();
}
}
}