Java暂停当前线程和继续的方式
程序员文章站
2023-12-28 17:31:58
...
(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();
可以跳过interrupt异常,继续往下执行。
(2)Object.wait() 与 Object.notify();
wait会阻塞当前线程,如果该线程被interrupt,也会产生interrupt异常。
(3)synchronized(object)块可以使当前线程阻塞,等获得object锁后继续执行。
(4) 使用Unsafe.park()与Unsafe.unpark();
推荐阅读
-
Java暂停当前线程和继续的方式
-
Java多线程创建方式和线程池的使用方法
-
Java中线程Thread的三种方式和对比
-
JAVA线程的概念和多线程的实现方式
-
Java并发编程:线程间协作的两种方式:wait、notify、notifyAll和Condition
-
java并发之线程间协作的两种方式:wait、notify、notifyAll和Condition
-
JAVA实现多线程的四种方式和 ThreadPoolExecutor线程池内容详解 七大参数 拒绝策略 自定义线程池
-
Java中线程Thread的三种方式和对比
-
Java多线程创建方式和线程池的使用方法
-
java中线程实现方式(execute和submit方式的区别)