(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();
Java暂停当前线程和继续的方式
猜你喜欢
转载自xiemingmei.iteye.com/blog/2261331
今日推荐
周排行