20 lines
694 B
Java
20 lines
694 B
Java
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,但是会有小概率会出现false,isInterrupted 所在的线程是否是中断状态,不清除状态标志
|
||
System.out.println("是否要停止1?=" + thread.isInterrupted());
|
||
System.out.println("是否要停止2?=" + thread.isInterrupted());
|
||
} catch (Exception exception) {
|
||
System.out.println("main catch");
|
||
exception.printStackTrace();
|
||
}
|
||
}
|
||
}
|