当我们使用Thread类来创建线程后,总是通过调用实例方法start()来启动线程,而线程在启动后一旦被线程调度器调度便会执行run()方法。那么问题来了,如果直接使用Thread实例调用run()方法,此时的执行线程会是谁呢?(主线程main or 子线程)
public class Test{
public static void main(String[] args) {
MyThread mt = new MyThread();
mt.run();
mt.start();
}
}
class MyThread extends Thread {
@Override
public void run() {
System.out.println("Current thread — " + Thread.currentThread().getName());
}
}