线程类的isInterrupted()方法是测试线程是否被中断的实例方法。它返回内部标志的值,真或假。如果线程被中断,那么它将返回真,否则返回假。
用法
public boolean isInterrupted()
返回
如果线程被中断则返回真,否则返回假。
示例
public class JavaIsInterruptedExp extends Thread
{
public void run()
{
for(int i=1;i<=3;i++)
{
System.out.println("doing task....:"+i);
}
}
public static void main(String args[])throws InterruptedException
{
JavaIsInterruptedExp t1=new JavaIsInterruptedExp();
JavaIsInterruptedExp t2=new JavaIsInterruptedExp();
// call run() method
t1.start();
t2.start();
System.out.println("is thread interrupted..:"+t1.isInterrupted());
System.out.println("is thread interrupted..:"+t2.isInterrupted());
// interrupt thread t1
t1.interrupt();
System.out.println("is thread interrupted..:" +t1.isInterrupted());
System.out.println("is thread interrupted..:"+t2.isInterrupted());
}
}
输出:
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 Thread isDaemon()用法及代码示例
- Java Thread isAlive()用法及代码示例
- Java Thread interrupted()用法及代码示例
- Java Thread interrupt()用法及代码示例
- Java Thread toString()用法及代码示例
- Java Thread setDefaultUncaughtExceptionHandler()用法及代码示例
- Java Thread suspend()用法及代码示例
- Java Thread destroy()用法及代码示例
- Java Thread holdLock()用法及代码示例
- Java Thread getContextClassLoader()用法及代码示例
- Java Thread setContextClassLoader()用法及代码示例
- Java Thread sleep()用法及代码示例
- Java Thread getThreadGroup()用法及代码示例
- Java Thread enumerate()用法及代码示例
- Java Thread notify()用法及代码示例
- Java Thread resume()用法及代码示例
- Java Thread activeCount()用法及代码示例
- Java Thread setDaemon()用法及代码示例
- Java Thread getId()用法及代码示例
- Java Thread setName()用法及代码示例
注:本文由纯净天空筛选整理自 Java Thread isInterrupted() method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。