透过Thread.join()和CountDownLatch来实现进程同步

通过Thread.join()和CountDownLatch来实现进程同步1.Thread.join()如果在一个进程,如main中调用另一个thre

通过Thread.join()和CountDownLatch来实现进程同步

1.Thread.join()

如果在一个进程,如main中调用另一个thread的join()函数会导致main函数阻塞,直至thread执行完毕。

Thread-1starts.Thread-4starts.Thread-0starts.all threads end.Thread-2starts.Thread-3starts.Thread-3 ends.Thread-1 ends.Thread-4 ends.Thread-0 ends.Thread-2 ends.