这是我的代码片段.
ExecutorService executor = Executors.newFixedThreadPool(ThreadPoolSize);
while(conditionTrue)
{
ClassImplementingRunnable c = new ClassImplementingRunnable();
executor.submit(c);
}
现在这样做了
executor.shutdown();
我想在这里实现的是,我想等待线程池中的所有线程完成执行,然后我想关闭执行程序.
但我想这不是这里发生的事情.主线程似乎正在执行关闭,它只是关闭所有东西.
在我的线程池大小为2之前,我做了以下操作,它似乎工作.
ClassImplementingRunnable c1 = new ClassImplementingRunnable();
executor.submit(c1);
ClassImplementingRunnable c2 = new ClassImplementingRunnable();
executor.submit(c2);
Future f1 = executor.submit(c1);
Future f2 = executor.submit(c2);
while(!f1.done || !f2.done)
{}
executor.submit();
我如何为线程池中的更多线程执行此操作?
谢谢.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)