首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

急等,关于一个线程阻塞的有关问题

2011-12-28 
急等,关于一个线程阻塞的问题我怎么样可以在一个线程,关掉另一个关掉一个阻塞中的线程(interrupt()不起作

急等,关于一个线程阻塞的问题
我怎么样可以在一个线程,关掉另一个关掉一个阻塞中的线程(interrupt()不起作用)
public   class   JobThread   extends   TimerTask   {
        List   map   =   new   ArrayList();

public   void   run()   {

for(int   i=0;i <map.size();i++){
    ManagerThread   th   =   (ManagerThread)   map.get(i);
    th.flag   =   false;
    th.interrupt();    
    System.out.println(th.getName()   +   "call   Timer   work ");
}
}
}


package   thread;

import   java.util.Timer;
public   class   ManagerThread   extends   Thread{



boolean   flag   =   true;

public   void   run()   {
long   now   =   System.currentTimeMillis();
while(flag){

  for(long   i=10000;i <10000000000L;i++){
  //   System.out.println( "运行中..... "+(i*i));
      }
        flag   =   false;
    }
  System.out.println(this.getName()+ "停止..... ");
              System.out.println( "11111111111           "+(System.currentTimeMillis()-now));
               
}


public   static   void   main(String[]   args)   {  

ManagerThread   th1   =   new   ManagerThread();
//ManagerThread   th2   =   new   ManagerThread();
JobThread   th3   =   new   JobThread();
//th3.map.add(th1);
//th3.map.add(th2);
th1.start();
//th2.start();
Timer   timer   =   new   Timer();
timer.schedule(th3,   1000);
}
}



[解决办法]
信号量
[解决办法]
试试把阻塞线程改成守护线程看看

热点排行