b.run()
doesn't start a new thread. It executes the run()
method on the main thread. And since that method contains an infinite loop, it never terminates, so a.start()
is never executed, and the second thread is never started.
You can either reverse the order of the calls:
a.start(); // first start the second thread
b.run(); // then run the infinite loop on the main thread
Or run b
's run()
method on a separate thread:
new Thread(() -> b.run()).start();
a.start();
Or if you change Y2
to implement Runnable
:
new Thread(b).start();
a.start();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…