[英]Java: design for using many executors services and only few threads
My 'test engine' will have n tests to perform, each one doing k sub-tests. 我的“测试引擎”将执行n个测试,每个测试执行k个子测试。 Each test result is stored for a later usage.
存储每个测试结果以供以后使用。
So I have n*k processes that can be ran concurrently. 因此,我有可以同时运行的n * k个进程。
I'm trying to figure how to use the java concurrent tools efficiently. 我试图弄清楚如何有效地使用Java并发工具。
Right now I have an executor service at test level and n executor service at sub test level. 现在,我在测试级别有一个执行程序服务,在子测试级别有n个执行程序服务。
I create my list of Callables for the test level. 我为测试级别创建了可调用对象列表。 Each test callable will then create another list of callables for the subtest level.
然后,每个可调用的测试将为子测试级别创建另一个可调用的列表。 When invoked a test callable will subsequently invoke all subtest callables
当调用测试可调用对象时,它将随后调用所有子测试可调用对象
call sequence: 通话顺序:
I can not share executor service since I need to call 'shutdown' on the executors. 我无法共享执行器服务,因为我需要在执行器上调用“关机”。
My idea to fix this problem is to provide the same fixed size thread pool to each executor service. 解决此问题的想法是为每个执行程序服务提供相同的固定大小的线程池。
Do you think it is a good design ? 您认为这是一个好的设计吗? Do I miss something more appropriate/simple for doing this ?
我会错过一些更合适/更简单的方法吗?
Use a single fixed thread pool executor. 使用单个固定线程池执行程序。 Avoid calling shutdown, if you are doing that you likely have some error.
避免调用shutdown,否则可能会出错。
Here is some pseudo-code that is my best guess at what you want with the little information posted. 这是一些伪代码,我可以根据所发布的少量信息对您的需求进行最佳猜测。
main () {
ArrayList<Future<?>> futures = new ArrayList<Future<?>>();
ExecutorService exec = Executors.newFixedThreadPool(Runtime.getNumProcessors())
futures.add(exec.submit(Test1));
...
futures.add(exec.submit(Testn));
for (Future<?> future:futures) {
? result = future.get();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.