写了一个关于 join 的小程序,发现了一个问题如下
package concurrent; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; public class Joining2 { public static void main(String[] args) { //ExecutorService exec = Executors.newCachedThreadPool(); Thread t2 = new Thread(new MusicPlay2()); Thread t1 = new Thread(new MusicPlay1(t2)); //exec.execute(t1); //exec.execute(t2); //exec.shutdown(); t1.start(); t2.start(); } } class MusicPlay1 implements Runnable { private int countDown = 10; private Thread thread; public MusicPlay1(Thread thread) { this.thread = thread; } @Override public void run() { while(true) { try { //TimeUnit.MICROSECONDS.sleep(1000); System.out.println(--countDown);