package com.currentcount.base;
/**
* 搭建了舞台线程
*
*
*/
public class Stage extends Thread {
//复写run方法
public void run(){
System.out.println("欢迎观看隋唐演义!");
try {
Thread.sleep(5000);
} catch (InterruptedException e2) {
e2.printStackTrace();
}
System.out.println("大幕徐徐拉开");
try {
Thread.sleep(5000);
} catch (InterruptedException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
System.out.println("话说隋朝末年,各路藩王和隋军杀的是昏天黑地");
ArmyRunnable armyTaskOfSuiDynasty=new ArmyRunnable();
ArmyRunnable armyTaskOfFarmer=new ArmyRunnable();
//使用Runnable创建线程
Thread armyOfSuiDynasty=new Thread(armyTaskOfSuiDynasty,"隋朝军队");
Thread armyOfFarmer=new Thread(armyTaskOfFarmer,"农民军队");
//线程的运行
armyOfSuiDynasty.start();
armyOfFarmer.start();
//让舞台线程休眠,大家能够专心观看军队的厮杀
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();}
try {
armyOfFarmer.join();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
System.out.println("正当双方激战正酣,半路杀出了个程咬金");
Thread Chengyaojin=new KeypersonThread();
Chengyaojin.setName("程咬金");
System.out.println("程咬金的理想就是结束战斗,使得百姓安居乐业");
//军队停止战斗
armyTaskOfSuiDynasty.keepRunning=false;
armyTaskOfFarmer.keepRunning=false;
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Chengyaojin.start();
//所有线程等待程咬金完成自己的历史使命
try {
Chengyaojin.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("程咬金完成了自己的理想,结束了战斗,使得人民能够安居乐业");
System.out.println("感谢观看隋唐演义!");
}