首页 > 编程语言 > 详细

线程 interrupt()方法简介

时间:2016-05-13 14:17:47      阅读:267      评论:0      收藏:0      [点我收藏+]

class T implements Runnable

{

   Thread t1,t2;

   T()

   {

      t1=new Thread(this);

      t2=new Thread(this);

    }

   public void run()

   {

      if(Thread.currentThread()==t2)

      {

         t1.interrupt();

 

      }

      if(Thread.currentThread()==t1)

      {

        System.out.println("线程t1开始运行!");

try{

          System.out.println("线程t1开始休眠10s!");

         t1.sleep(10000);

         }

      catch(InterruptedException e)

         {

           System.out.println("线程t1被吵醒了!");

          } 

      }

   }

}

class A 

{

   public static void main(String args[])

   {   

      T t=new T();

      t.t1.start();

      t.t2.start();

    }

}

线程 interrupt()方法简介

原文:http://www.cnblogs.com/sxdxjava/p/5487588.html

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