無限死循環(huán)了
public class wutai extends Thread {
public void run(){
CarryRunable zfj=new CarryRunable();
CarryRunable fpj=new CarryRunable();
//使用runnable創(chuàng)建線程
Thread zfzgj=new Thread(zfj,"政府正規(guī)軍");
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("政府軍表示我們有核彈定點(diǎn)打擊了");
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+"個(gè)");
}
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+"個(gè)");
Thread.yield();
}
}
}
}
2016-04-24
你把wutai 這個(gè)class改成如上就ok了。你catch exception的括號寫錯(cuò)了
2016-03-30
把CarryRunable和KeySonThread的代碼也貼出來