Java 线程 isInterrupted() 方法

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

线程类的 isInterrupted() 方法是一个实例方法,用于测试线程是否已被中断。它返回内部标志的值,为 true 或 false。如果线程被中断,则返回 true,否则返回 false。

语法

返回

如果线程已被中断,它将返回 true,否则返回 false。

示例

输出

is thread interrupted..: false
is thread interrupted..: false
is thread interrupted..: true
is thread interrupted..: false
doing task....: 1
doing task....: 2
doing task....: 3
doing task....: 1
doing task....: 2
doing task....: 3
 
下一主题Java 线程