亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

無限死循環了


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
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號