public class RabbitAndTorbit {
/**
* @param args
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
Rabbit rabbit=new Rabbit();
Torbit torbit=new Torbit();
Thread trTorbit=new Thread(torbit);
Thread trRabbit=new Thread(rabbit);
for(int i=0;i<10;i++){
if(i%2==0){
trRabbit.start();
}
else{
trTorbit.join();
}
System.out.println("第"+(i+1)+"回合");
}
}
}
class Rabbit implements Runnable{
@Override
public void run() {
int i=0;
// TODO Auto-generated method stub
while( i<6){
System.out.println("Rabbit is in the lead!!!! ");
i++;
}
i=0;
}
}
class Torbit implements Runnable{
@Override
public void run() {
int i=0;
// TODO Auto-generated method stub
while(i<6){
System.out.println("Torbit is in thd lead!!!");
i++;
}
i=0;
}
}
上面是代码 抛出IllegalThreadStateException 异常
应该怎么写,求指教 |