Java ThreadGroup interrupt() 方法

2024 年 11 月 11 日 | 阅读 1 分钟

ThreadGroup 类的 interrupt() 方法用于中断线程组中的所有线程。

语法

返回

此方法不返回任何值。

Exception

SecurityException: 如果当前线程不允许访问线程组或线程组中的任何线程,则会抛出此异常。

示例

输出

Thread-1 starts
Thread-2 starts
Thread-1 interrupted
Thread-1 completed executing
Thread-2 completed executing