Java Thread destroy() 方法

2025年3月21日 | 阅读 1 分钟

线程类的 destroy() 方法用于销毁线程组及其所有子线程组。线程组必须是空的,表示线程组中的所有线程都已停止。

语法

返回

它不返回任何值。

Exception

IllegalThreadStateException: 如果线程组不为空或线程组已被销毁,则抛出此异常。

SecurityException: 如果当前线程无法修改此线程组。

示例

输出

Thread-1 finished executing
Thread-2 finished executing
child thread destroyed
Parent thread destroyed
 
下一主题Java 多线程