LockSupport
LockSupport:可以让线程阻塞,可以唤醒指定的线程
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;
public class T13_TestLockSupport {
public static void main(String[] args) {
Thread t = new Thread(()->{
for (int i = 0; i < 10; i++) {
System.out.println(i);
if(i == 5) {
LockSupport.park();
}
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
t.start();
LockSupport.unpark(t);
/*try {
TimeUnit.SECONDS.sleep(8);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("after 8 senconds!");
LockSupport.unpark(t);*/
}
}
以上是 LockSupport 的全部内容, 来源链接: utcz.com/z/519022.html