package com.imooc.concurrent.base;
//隋唐演义大舞台
public class Stage extends Thread {
public void run(){
//创建军队的作战任务,
ArmyRunnable armyTaskOfSuiDynasty=new ArmyRunnable();
ArmyRunnable armyTaskOfRevolt=new ArmyRunnable();
//创建军队线程
//使用Runnable接口创建线程
Thread armyOfSuiDynasty=new Thread(armyTaskOfSuiDynasty,"隋军");
Thread armyOfRevolt=new Thread(armyTaskOfRevolt,"农民军");
//启动线程,让军队开始作战
armyOfSuiDynasty.start();
armyOfRevolt.start();
//舞台线程休眠,大家专心观看军队作战
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
armyTaskOfSuiDynasty.keepRunning=false;
armyTaskOfRevolt.keepRunning=false;
try {
armyOfRevolt.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[]args){
new Stage().start();
}
}