首页 > 编程语言 > 详细

InterruptionInJava

时间:2018-11-30 12:36:20      阅读:125      评论:0      收藏:0      [点我收藏+]
package com.test;

public class InterruptionInJava implements Runnable{
  
  public static void main(String[] args) throws InterruptedException {
      Thread testThread = new Thread(new InterruptionInJava(),"InterruptionInJava");
      //start thread
      testThread.start();
     
      //interrupt thread
      testThread.interrupt();

      System.out.println("main end");

  }

  @Override
  public void run() {
    try {
      Thread.sleep(10000);
    } catch (InterruptedException e) {
      System.out.println(Thread.currentThread().isInterrupted());
      Thread.currentThread().interrupt();
      System.out.println(Thread.currentThread().isInterrupted());
    }
      while(true){
          if(Thread.currentThread().isInterrupted()){
              System.out.println("Yes,I am interruted,but I am still running");

          }else{
              System.out.println("not yet interrupted");
          }
      }
  }
}

 

InterruptionInJava

原文:https://www.cnblogs.com/tonggc1668/p/10043217.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!