同时启动了三个线程,如何让三个线程同时进入等待?然后一个个唤醒?帮写两个方法
publicclassMainClassextendsThread{publicstaticMainClassmain1;publicstaticMainClassmai...
public class MainClass extends Thread {
public static MainClass main1;
public static MainClass main2;
public static MainClass main2;
public void run(){
while(true){
System.out.println(this.getName());
}
}
public static void doRun(){
main1=new MainClass();
main1.start();
main2=new MainClass();
main2.start();
main3=new MainClass();
main3.start();
}
public static void main(String[] args) {
MainClass.doRun();
}
} 展开
public static MainClass main1;
public static MainClass main2;
public static MainClass main2;
public void run(){
while(true){
System.out.println(this.getName());
}
}
public static void doRun(){
main1=new MainClass();
main1.start();
main2=new MainClass();
main2.start();
main3=new MainClass();
main3.start();
}
public static void main(String[] args) {
MainClass.doRun();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询