778 |
|
* necessarily individually slow because they must block. |
779 |
|
*/ |
780 |
|
void testInParallel(Action ... actions) { |
781 |
< |
ExecutorService pool = Executors.newCachedThreadPool(); |
782 |
< |
try { |
781 |
> |
try (PoolCloser<ExecutorService> poolCloser |
782 |
> |
= new PoolCloser<>(Executors.newCachedThreadPool())) { |
783 |
> |
ExecutorService pool = poolCloser.pool; |
784 |
|
ArrayList<Future<?>> futures = new ArrayList<>(actions.length); |
785 |
|
for (final Action action : actions) |
786 |
|
futures.add(pool.submit(new CheckedRunnable() { |
793 |
|
} catch (Exception ex) { |
794 |
|
threadUnexpectedException(ex); |
795 |
|
} |
795 |
– |
} finally { |
796 |
– |
joinPool(pool); |
796 |
|
} |
797 |
|
} |
798 |
|
|