这里为什么没有用start()方法而是用了run()方法呢?
这里方法run()称为线程体,它包含了要执行的这个线程的内容, Run方法运行结束, 此线程终止。然后CPU再调度其它线程。如果调用start(),线程执行的结果可能是乱序的
/**
* 三个线程
* 打印十行ABC
*/
public class ThreadDemo1 {public static void main(String[] args) throws InterruptedException {
show();
}
private static void show() throws InterruptedException {
for(int i=0;i<10;i++) {
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
System.out.print("A");
}
});
t1.run();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
System.out.print("B");
}
});
t2.run();
Thread t3 = new Thread(new Runnable() {
@Override
public void run() {
System.out.println("C");
}
});
t3.run();
}
}
}