转换图片路径为相对路径
This commit is contained in:
@ -0,0 +1,17 @@
|
||||
package com.heibaiying.interrupt;
|
||||
|
||||
/**
|
||||
* interrupt() 只是设置中断标志位,并不能中断线程
|
||||
*/
|
||||
public class J1_Interrupt {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
Thread thread = new Thread(() -> {
|
||||
while (true) {
|
||||
System.out.println("子线程打印");
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
Thread.sleep(10);
|
||||
thread.interrupt();
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.heibaiying.interrupt;
|
||||
|
||||
/**
|
||||
* isInterrupted() 用于检查当前线程是否存在中断标志位
|
||||
*/
|
||||
public class J2_IsInterrupted {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
Thread thread = new Thread(() -> {
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
System.out.println("子线程打印");
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
Thread.sleep(10);
|
||||
thread.interrupt();
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.heibaiying.interrupt;
|
||||
|
||||
/**
|
||||
* 判断当前线程的中断状态,并清除当前线程的中断标志位
|
||||
*/
|
||||
public class J3_Interrupted {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
Thread thread = new Thread(() -> {
|
||||
while (!Thread.interrupted() || !Thread.currentThread().isInterrupted()) {
|
||||
System.out.println("子线程打印");
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
Thread.sleep(10);
|
||||
thread.interrupt();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user