Thread 的join

前端之家收集整理的这篇文章主要介绍了Thread 的join前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Context:

threadObject:为Thread对象(以下带至)

Thread的Join方法

1.会暂停当前的线程,运行调用方法的Thread对象所对应的线程将开始履行。


注意点:

1.Thread内部有个判断isAlive() 判断,注释是Tests if this thread is alive. A thread is alive if it has been started and has not yet died.也就是说没有threadObject.start(),threadObject.join()是肯定不会运行的。另外如果threadObject已履行完了,threadObject.join()也不会有作用。


Tips:

1.当调用threadObject.interrupt()后,其实不会立即终止threadObject所对应的线程。所以为了保证尽快终止,可以立即调用threadObject.join()方法让它尽快运行,以后终止。

猜你在找的PHP相关文章