为了账号安全,请及时绑定邮箱和手机立即绑定

无限死循环了


public class wutai extends Thread {

public void run(){

CarryRunable zfj=new CarryRunable();

CarryRunable fpj=new CarryRunable();

//使用runnable创建线程

Thread zfzgj=new Thread(zfj,"政府正规军");

Thread fpzyj=new Thread(fpj,"反叛志愿军");

zfzgj.start();

fpzyj.start();

//线程的启动

try {

Thread.sleep(50);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

System.out.println("政府军表示我们有核弹定点打击了");

System.out.println("志愿军表示我们什么都怕就是不怕污染");

Thread dg=new KeySonThread();

dg.setName("良辰路过");

zfj.jundui=false;

fpj.jundui=false;

try {

Thread.sleep(2000);

} catch (InterruptedException e1) {

e1.printStackTrace();

}

dg.start();

}

try {

fpzyj.join();

} catch (InterruptedException e) {

e.printStackTrace();

}

System.out.println("良辰有100种方法让你分分钟KO");

}


public static void main(String[] args) {

new wutai().start();

}

}

public class KeySonThread extends Thread {

public void run(){

System.out.println(Thread.currentThread().getName()+"上菜了");

for(int i=0;i<10;i++){

System.out.println(Thread.currentThread().getName()+"突然就咬死了"+i+"个");

}

System.out.println(Thread.currentThread().getName()+"歇菜");

}

}

public class CarryRunable implements Runnable {

volatile boolean jundui=true;

@Override

public void run() {

// TODO Auto-generated method stub

while(jundui){

for(int i=0;i<5;i++){

System.out.println(Thread.currentThread().getName()+"搞死了"+i+"个");

Thread.yield();

}

}

}


}


正在回答

2 回答

package com.imooc.thread;

public class wutai extends Thread {
	public void run() {
		CarryRunable zfj = new CarryRunable();
		CarryRunable fpj = new CarryRunable();
		// 使用runnable创建线程
		Thread zfzgj = new Thread(zfj, "政府正规军");
		Thread fpzyj = new Thread(fpj, "反叛志愿军");
		zfzgj.start();
		fpzyj.start();
		// 线程的启动
		try {
			Thread.sleep(50);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
			System.out.println("政府军表示我们有核弹定点打击了");
			System.out.println("志愿军表示我们什么都怕就是不怕污染");
			Thread dg = new KeySonThread();
			dg.setName("良辰路过");
			zfj.jundui = false;
			fpj.jundui = false;
			try {
				Thread.sleep(2000);
			} catch (InterruptedException e1) {
				e1.printStackTrace();
			}
			dg.start();
		try {
			fpzyj.join();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("良辰有100种方法让你分分钟KO");
	}

	public static void main(String[] args) {
		new wutai().start();
	}
}

你把wutai 这个class改成如上就ok了。你catch exception的括号写错了

0 回复 有任何疑惑可以回复我~
#1

慕前端0336099 提问者

非常感谢!
2016-04-25 回复 有任何疑惑可以回复我~

把CarryRunable和KeySonThread的代码也贴出来


0 回复 有任何疑惑可以回复我~
#1

慕前端0336099 提问者

大神给帮看下撒
2016-04-02 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

无限死循环了

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号