Thread 的join
发布时间:2020-12-13 20:10:40 所属栏目:PHP教程 来源:网络整理
导读:Context: threadObject:为Thread对象(以下带至) Thread的Join方法: 1.会暂停当前的线程,运行调用该方法的Thread对象所对应的线程将开始履行。 注意点: 1.Thread内部有个判断isAlive() 判断,注释是Tests if this thread is alive. A thread is alive i
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()方法让它尽快运行,以后终止。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |