class Demoextends extends Thread
{
private int x=10;
public void run()
{
while(x>0)
{
System.out.println(Thread.currentThread().getName()+" extends:"+x--);
}
}
}
class demo
{
public static void main(String[] argv)
{
Demoextends d1 = new Demoextends();
Demoextends d2 = new Demoextends();
d1.start();
d2.start();
d1.run();
d2.run();
}
}
---------- java ----------
main extends:10
main extends:8
main extends:7
main extends:6
main extends:5
main extends:4
main extends:3
main extends:2
main extends:1
main extends:9
main extends:8
main extends:7
main extends:6
main extends:5
main extends:4
main extends:3
main extends:2
main extends:1
Thread-0 extends:9
Thread-1 extends:10
输出完成 (耗时 0 秒) - 正常终止
为什么输出的是这个 我明明创建了两个线程 求解 |