代码程序: public static void main(String[] args) { System.out.println("start"); Thread thread = new Thread(){ public void run(){ System.out.println(1); } }; thread.start(); Thread thread2 = new Thread(){ public void run(){ System.out.println(2); } }; thread2.start(); Thread thread3 = new Thread(){ public void run(){ System.out.println(3); } }; thread3.start(); Thread thread4 = new Thread(){ public void run(){ System.out.println(4); } }; thread4.start(); Thread thread5 = new Thread(){ public void run(){ System.out.println(5); } }; thread5.start(); Thread thread6 = new Thread(){ public void run(){ System.out.println(6); } }; thread6.start(); Thread thread7 = new Thread(){ public void run(){ System.out.println(7); } }; thread7.start(); Thread thread8 = new Thread(){ public void run(){ System.out.println(8); } }; thread8.start(); Thread thread9 = new Thread(){ public void run(){ System.out.println(9); } }; thread9.start(); System.out.println("end"); }
运行结果:
start
end
1
2
4
3
7
9
5
8
6