gpt4 book ai didi

java - 如何连接任意两个特定线程?

转载 作者:太空宇宙 更新时间:2023-11-04 11:54:49 24 4
gpt4 key购买 nike

我是多线程新手。如果有人能消除我的疑虑,我会很高兴。

我有 3 个线程 t1、t2 和 t3。如果我像下面这样在 t1 上使用 join,则所有其他线程都会等待 t1 完成。我是否可以让 t2 等待 t1 完成,以便 t1 和 t3 可以同时运行?

    t1.start();
t1.join();
t2.start();
t3.start();

最佳答案

If I use join on t1 like below, all other threads wait for t1 to finish.

没有。只有执行 t1.join() 调用的线程才会等待 t1 完成。所有其他线程继续。

Is it possible that I could make just t2 to wait for t1 to finish, so that t1 and t3 can run concurrently?

t2 线程上运行的代码执行 t1.join()

关于java - 如何连接任意两个特定线程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41464665/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com