我需要加入多个线程超时。类似于Thread.join(long millis)
,但适用于多个线程。加入多个线程超时
我发现一些关于加入多个线程的帖子,但不是关于超时加入。
我改变的代码是:
for (Thread thread : threads) {
thread.join(units.toMillis(timeout));
}
但这显然等待分别具有轮候长达threads.length * timeout
效果每个线程。我想完全等待所有线程的timeout
。
什么是正确的方法来做到这一点?
这似乎有点含糊。你可以发布你到目前为止的代码吗? – bhspencer
@bhspencer我会将代码添加到我的帖子中。 – traveh