了解join() [英] Understanding join()

查看:118
本文介绍了了解join()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设线程 A 正在运行。我有另一个帖子, B ,谁不是。 B已经启动,处于可运行状态。

Suppose a thread A is running. I have another thread, B, who's not. B has been started, is on runnable state.

如果我打电话会怎样? B.join()

What happens if I call: B.join()?

它会暂停执行 A 还是会等待A的 run() 要完成的方法?

Will it suspend the execution of A or will it wait for A's run() method to complete?

推荐答案

join()将使当前正在执行的线程等待它的线程被叫去死。

join() will make the currently executing thread to wait for the the thread it is called on to die.

所以 - 如果A正在运行,你调用B.join(),A将停止执行,直到B结束/死亡。

So - If A is running, and you call B.join(), A will stop executing until B ends/dies.

这篇关于了解join()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆