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


Tips:

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值