package com.freeflying.thread.base;
/**
* @ClassName: TestVisitSeqByStart
* @Description:测试线程执行start方法的顺序并不代表线程的启动顺序
* @author freeflying
* @date 2018年6月21日
*/
public class TestVisitSeqByStart {
public static void main(String[] args) {
MyThreadByStart myThreadByStart1=new MyThreadByStart(1);
MyThreadByStart myThreadByStart2=new MyThreadByStart(2);
MyThreadByStart myThreadByStart3=new MyThreadByStart(3);
MyThreadByStart myThreadByStart4=new MyThreadByStart(4);
MyThreadByStart myThreadByStart5=new MyThreadByStart(5);
MyThreadByStart myThreadByStart6=new MyThreadByStart(6);
MyThreadByStart myThreadByStart7=new MyThreadByStart(7);
MyThreadByStart myThreadByStart8=new MyThreadByStart(8);
MyThreadByStart myThreadByStart9=new MyThreadByStart(9);
MyThreadByStart myThreadByStart0=new MyThreadByStart(0);
myThreadByStart0.start();
myThreadByStart1.start();
myThreadByStart2.start();
myThreadByStart3.start();
myThreadByStart4.start();
myThreadByStart5.start();
myThreadByStart6.start();
myThreadByStart7.start();
myThreadByStart8.start();
myThreadByStart9.start();
}
}
class MyThreadByStart extends Thread{
private int i;
public MyThreadByStart(int i) {
this.i=i;
}
@Override
public void run() {
System.out.println(i);
}
}
运行结果:
1
5
9
3
7
2
6
0
4
8