如下所示,我将断点打在//断点1 这个位置,但是调试的时候run方法进不去,但是程序始终处于运行状态,请教大家,怎样进行多线程程序的调试?
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
class MyThread extends Thread{
private String taskID;
public MyThread(String taskID){
this.taskID=taskID;
}
public void run(){ // 断点1
for (int i = 0; i < 3; i++) {
try {
Thread.sleep(500);// 为了测试出效果,让每次任务执行都需要一定时间
System.out.println(taskID+"-"+i+"睡眠中");
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("第 "+taskID+" 次任务的第 "+i+" 次执行");
}
}
}
public class ExecutorTest {
public static void main(String[] args) {
// 创建可以容纳3个线程的线程池
ExecutorService fixedThreadPool = Executors.newFixedThreadPool(3);
MyThread myThread1=new MyThread("0");
fixedThreadPool.execute(myThread1);
MyThread myThread2=new MyThread("1");
fixedThreadPool.execute(myThread2);
MyThread myThread3=new MyThread("2");
fixedThreadPool.execute(myThread3);
fixedThreadPool.shutdown();
while(true){
if(fixedThreadPool.isTerminated()){
System.out.println("所有计算完毕!");
break;
}
}
}
}