急等,关于一个线程阻塞的问题
我怎么样可以在一个线程,关掉另一个关掉一个阻塞中的线程(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);
}
}
------解决方案--------------------信号量
------解决方案--------------------试试把阻塞线程改成守护线程看看