public class ThreadDemo4 {
static class MyThread extends Thread {
@Override
public void run() {
System.out.println("新线程");
}
}
public static void main(String[] args) {
Thread t = new MyThread();
t.run();
//t.start();
}
}
public class ThreadDemo4 {
static class MyThread extends Thread {
@Override
public void run() {
System.out.println("新线程");
}
}
public static void main(String[] args) {
Thread t = new MyThread();
//t.run();
t.start();
}
}
t.run(); 这只是一个普通的方法调用,没有创建新的线程,输出语句中是在原线程中执行的。
t.start(); 这是要创建一个新的线程,由新的线程来执行输出。而调用 start() 方法,就是喊一声:”行动起来!“,线程才真正独立去执行了。