最近用到了这样的一个功能,主进程需要等待一段功能完成后再继续运行,例如计算这段功能运行的时间。原来的实现使用了最基本的wait/notify来实现,后来发现了thread的join功能,发现用这个来实现更合理。
原理如下:
main thread.
...
thread func;
func.start();
func.join();
...// the main thread will go on running after the func thread died.refer to:http://www.blogjava.net/jnbzwm/articles/330549.html
本文介绍了一种使用Thread的join方法控制主线程等待子线程结束的技术。相比于传统的wait/notify机制,join方法提供了更为简便的方式实现线程间的同步。
637

被折叠的 条评论
为什么被折叠?



