線程類的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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。