public static void main(String[] args) {
Thread t = new Thread(()->{
for (int i = 0; i < 10; i++) {
System.out.println(i);
if (i == 3){
LockSupport.park(); //当前线程停止
}
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
t.start();
try {
TimeUnit.SECONDS.sleep(6);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("main线程6秒后");
LockSupport.unpark(t); //t线程继续执行
}
juc下locks之LockSupport
猜你喜欢
转载自blog.csdn.net/Forest24/article/details/101536978
今日推荐
周排行