代码运行结果线程显示混乱,看不出问提出在哪?
package com.imooc;
public class Stage extends Thread {
public void run()
{
System.out.println("欢迎观看隋唐演义");
try {
Thread.sleep(5000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("大幕徐徐拉开");
//舞台线程休眠
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
Thread.sleep(5000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("话说隋朝末年,隋军与农民起义军杀的昏天黑地");
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 e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("双方激战正酣,半路杀出个程咬金");
Thread mrCheng = new KeyPersonThread();
mrCheng.setName("程咬金");
System.out.println("程咬金的理想就是结束战争,使百姓安居乐业!");
//军队停止作战
armyTaskOfSuiDynasty.Keeprunning = false;
armyTaskOfRevolt.Keeprunning = false;
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mrCheng.start();
try {
mrCheng.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("战争结束,人民安居乐业,程先生实现了积极的人生梦想,为人民做出贡献");
System.out.println("隋唐演义结束,谢谢");
}
public static void main(String[] args) {
new Stage().start();
}
}
这是运行结果混乱部分的截图