The following code works, fine, but i wonder .. conceptually, is it correct? Start the threads, wait for them to join
. Should ThreadPool
be used instead?
If possible, please comment
List<Thread> threads = new ArrayList<Thread>();
for (Test test : testsToBeExecuted) {
Thread t = new Thread(test);
threads.add(t);
t.start();
}
for (Thread thread : threads) {
thread.join();
}
Conceptually it looks fine. You can use an ExecutorService which you create one like:
ExecutorService service = Executors.newFixedThreadPool(testsToBeExecuted.size());
Thenyou would create a list of Callables and invokeAll on the executor service itself. That in essence will do the same thing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With