java 多线程join
java 多线程 join
官方文档中解析是:
The join method allows one thread to wait for the completion of another. If t is a Thread object whose thread is currently executing,
t.join();
causes the current thread to pause execution until t’s thread terminates. Overloads of join allow the programmer to specify a waiting period. However, as with sleep, join is dependent on the OS for timing, so you should not assume that join will wait exactly as long as you specify.
Like sleep, join responds to an interrupt by exiting with an InterruptedException.
其实已经解析得很清楚了,执行线程t.join()方法,那么当前执行得线程就会等待t继续执行。产生一个类似于阻塞的效果,但其实jion内部是调用了wait(),也就是会让当前执行的线程休眠。
#概念(3)评论