线程状态
<font color="#7985ec">初始(New)</font>
Thread 类
Runnable 接口
✔ Callable 接口
<font color="#7985ec">可运行(Runnable)</font>
准备(Ready):等待分配 CPU 资源
运行(Running):正在运行
休眠(Sleeping)
<font color="#7985ec">等待(Waiting):等待其他线程唤醒分配 CPU 时间片</font>
<font color="#7985ec">定时等待(Time Waiting):定时自动唤醒分配 CPU 时间片</font>
<font color="#7985ec">阻塞(Blocked):等待获取排它锁,其线程释放锁即结束此状态</font><br>
<font color="#7985ec">终止(Terminated)</font>
线程操作
线程中断
InterruptedException
interrupted()
Executor 的中断
Executor.shutdown()
future.cancel(true)
安全取消线程
检测 isInterrupted 处理中断
Future 限时运行
停止线程池
应用实例
BlockingQueue
<div>ExecutorService</div>
毒丸对象(Poison Pill)
使用关闭钩子正确关闭 JVM
使用守护线程
实现 UncaughtException 接口处理 RuntimeException
线程组
线程通信
等待 await - 通知 signal
与 sleep 的对比
notify 与 notifyAll
wait 的范式
共享变量同步
管道流
线程协作 join