Java: design for using many executors services and only few threads

Posted by Guillaume on Stack Overflow See other posts from Stack Overflow or by Guillaume
Published on 2010-06-08T11:07:48Z Indexed on 2010/06/08 11:12 UTC
Read the original article Hit count: 243

I need to run in parallel multiple threads to perform some tests.

My 'test engine' will have n tests to perform, each one doing k sub-tests. Each test result is stored for a later usage.

So I have n*k processes that can be ran concurrently.

I'm trying to figure how to use the java concurrent tools efficiently.

Right now I have an executor service at test level and n executor service at sub test level.

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

  • test 1
    • subtest a1
    • subtest ...1
    • subtest k1
  • test n
    • subtest a2
    • subtest ...2
    • subtest k2

call sequence:

  • test manager create test 1 callable
    • test1 callable create subtest a1 to k1
    • testn callable create subtest an to kn
  • test manager invoke all test callables
    • test1 callable invoke all subtest a1 to k1
    • testn callable invoke all subtest an to kn

This is working fine, but I have a lot of new treads that are created.

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 ?

© Stack Overflow or respective owner

Related posts about java

Related posts about multithreading