且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java线程-第一个线程完成时关闭其他线程

更新时间:2022-11-09 13:57:28

我会尝试在每个bot中使用boolean isRunning,在run方法中使用while(isRunning).然后在第四个线程中,检查所有的机器人,看看是否完成了.如果已完成,请将其他机器人的isRunning设置为false,它们应退出.

I would try having a boolean isRunning in each bot and in the run method have a while(isRunning). Then in a fourth thread, check through all of the bots and see if any are done. If one is done, set the isRunning of the others bots to false and they should exit.