欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Java暂停当前线程和继续的方式

程序员文章站 2023-12-28 19:10:22
...
(1) Thread.currentThread().sleep() 与  Thread.currentThread().interrupt();
可以跳过interrupt异常,继续往下执行。


(2)Object.wait() 与 Object.notify();
wait会阻塞当前线程,如果该线程被interrupt,也会产生interrupt异常。


(3)synchronized(object)块可以使当前线程阻塞,等获得object锁后继续执行。


(4) 使用Unsafe.park()与Unsafe.unpark();





上一篇:

下一篇: