/** * Await successful completion of all submitted tasks. Throw exception of the first failed task * if 1 or more tasks failed. * * After this call completes, the thread pool will be shut down. * * @throws ExecutionException if a computation threw an * exception * @throws InterruptedException if the current thread was interrupted * while waiting */ public void awaitSuccessfulCompletion() throws InterruptedException, ExecutionException { awaitUninterruptibly(); for (final Future<?> f : futures) { f.get(); } }
@Test public void testEvenNumbersMultipleThread() { for (int j = 0; j < 10; j++) { int maxValue = 500000; sparseBitSet = new HollowSparseIntegerSet.SparseBitSet(maxValue); SimultaneousExecutor executor = new SimultaneousExecutor(); int parallelism = executor.getMaximumPoolSize(); int taskSize = maxValue / parallelism; for (int i = 0; i < parallelism; i++) { int from = i * taskSize; int to = (from + taskSize) - 1; if (i == (parallelism - 1)) to = maxValue; executor.submit(new Task(sparseBitSet, from, to)); } executor.awaitUninterruptibly(); HollowSparseIntegerSet.SparseBitSet.compact(sparseBitSet); Assert.assertTrue(sparseBitSet.cardinality() == 250001); } }