我看到了有趣的行为。我正在运行这段代码
public class ThreadsTest {
public static void main(String[] args) {
Runnable mr = new MyRunnable();
Thread t1 = new Thread(mr);
Thread t2 = new Thread(mr);
t1.setName("first");
t2.setName("second");
t1.start();
t2.start();
t1.run();
}
}
class MyRunnable implements Runnable {
public void run() {
for (int i=0; i < 2; i++) {
System.out.println("Running: " + Thread.currentThread().getName());
}
}
}
我得到的输出是:
Running: first
Running: first
Running: second
Running: second
我期待看到类似的东西:
Running: first
Running: first
Running: second
Running: second
Running: main
Running: main
有谁知道为什么我Running: main
在输出中看不到某处。谢谢你。