1 public static void main(String args[]) {
2
3
4 Thread t1=
new Thread(){
5 public void run(){
6 System.out.println("1"
);
7 }
8 };
9 Thread t2=
new Thread(){
10 public void run(){
11 System.out.println("2"
);
12 }
13 };
14 t1.run();
15 t2.start();
16
17 System.out.println("3"
);
18
19
20
21
22 }
输出结果:
start()方法来启动线程,真正实现了多线程运行,main为主线程,所以3先于2输出
run()方法当作普通方法的方式调用,程序还是要顺序执行,程序执行路径还是就一条,并没有达到写线程的目的。
转载于:https://www.cnblogs.com/LingRenne/p/7802844.html