Thread 的join

来源:互联网 发布:淘宝托鞋 编辑:程序博客网 时间:2024/05/13 06:36

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.也就是说在Thread对象之前没有threadObject.start(),threadObject.join()是肯定不会运行的。另外如果threadObject已经执行完了,threadObject.join()也不会有作用。


Tips:

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

0 0