ForkJoinPool pool = new ForkJoinPool(parallelism); try { pool.submit(() -> taskIndices.forEach(task::accept)).get(); } catch (InterruptedException e) { throw new IllegalStateException(e);
ForkJoinPool pool = new ForkJoinPool(parallelism); try { return pool.submit(() -> taskIndices.mapToObj(task::apply).collect(collector)).get(); } catch (InterruptedException e) { throw new IllegalStateException(e);
return ret; }))).get(); } catch (InterruptedException|ExecutionException e) { int successCount = successCounter.intValue();
protected List<Path> writeParallel(Configuration hadoopConfig, Map<Path, List<byte[]>> toWrite, int parallelism) throws IOException { List<Path> outFiles = Collections.synchronizedList(new ArrayList<>()); ForkJoinPool tp = new ForkJoinPool(parallelism); try { tp.submit(() -> { toWrite.entrySet().parallelStream().forEach(e -> { Path path = e.getKey(); List<byte[]> data = e.getValue(); if (data.size() > 0) { try { write(getResultsWriter(), hadoopConfig, data, path); } catch (IOException ioe) { throw new RuntimeException( String.format("Failed to write results to path '%s'", path.toString()), ioe); } outFiles.add(path); } }); }).get(); } catch (InterruptedException | ExecutionException e) { throw new IOException("Error finalizing results.", e); } catch (RuntimeException e) { throw new IOException(e.getMessage(), e.getCause()); } outFiles.sort((o1, o2) -> o1.getName().compareTo(o2.getName())); return outFiles; }
).get(); } catch (Exception e) { throw new IllegalStateException(e.getMessage(), e);
private int getNumberOfBatches(final ReaderSpliterator spliterator) throws ExecutionException, InterruptedException { final AtomicInteger numSplits = new AtomicInteger(0); //we want to wrap the spliterator and count the (valid) splits Spliterator<String> delegatingSpliterator = spy(spliterator); doAnswer(invocationOnMock -> { Spliterator<String> ret = spliterator.trySplit(); if(ret != null) { numSplits.incrementAndGet(); } return ret; }).when(delegatingSpliterator).trySplit(); Stream<String> stream = StreamSupport.stream(delegatingSpliterator, true); //now run it in a parallel pool and do some calculation that doesn't really matter. ForkJoinPool forkJoinPool = ForkJoinPool.commonPool(); forkJoinPool.submit(() -> { Map<String, Integer> threads = stream.parallel().map(s -> Thread.currentThread().getName()) .collect(Collectors.toMap(s -> s, s -> 1, Integer::sum)); Assert.assertTrue(threads.size() > 0); } ).get(); return numSplits.get(); }
private List<AppStatus> getStreamsStatuses(List<String> streamNames) { try { return this.forkJoinPool.submit(() -> streamNames.stream().parallel() .map(this::skipperStatus).flatMap(List::stream).collect(Collectors.toList())).get(); } catch (Exception e) { logger.error("Failed to retrieve the Runtime Stream Statues", e); throw new RuntimeException("Failed to retrieve the Runtime Stream Statues for " + streamNames); } }
private List<AppStatus> getStreamStatuses(Pageable pageable, List<String> skipperStreamNames) throws ExecutionException, InterruptedException { return this.forkJoinPool.submit(() -> skipperStreamNames.stream().parallel() .map(this::skipperStatus).flatMap(List::stream).collect(Collectors.toList())).get(); }
ForkJoinTask<String> fjt=new RecursiveTask<String>() { protected String compute() { return "hello "+Thread.currentThread(); } }; fjt.invoke(); System.out.println(fjt.get());
@Override protected <U> U terminateConcrete( @Nonnull final ThrowingSupplier<U, RuntimeException> supplier) throws InterruptedException { try { return threads.submit(supplier::get).get(); } catch (final ExecutionException e) { return handleForkJoinPoolAsObject(e); } }
@Override protected boolean terminateBoolean( @Nonnull final ThrowingBooleanSupplier<RuntimeException> supplier) throws InterruptedException { try { return threads.submit(supplier::getAsBoolean).get(); } catch (final ExecutionException e) { return handleForkJoinPoolAsBoolean(e); } }
@Override protected void terminateVoid(@Nonnull final ThrowingRunnable<RuntimeException> action) throws InterruptedException { try { threads.submit(() -> { action.run(); return null; }).get(); } catch (final ExecutionException e) { handleForkJoinPoolAsObject(e); } }
private Stopwatch put(List<? extends RevObject> objects) { Stopwatch sw = Stopwatch.createStarted(); try { forkJoinPool.submit(() -> objects.parallelStream().forEach(cache::put)).get(); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); throw new RuntimeException(); } return sw.stop(); }
public void sortAscending() { if ((myDelegate instanceof Mutate1D.Sortable) && (this.count() == myDelegate.count())) { ((Mutate1D.Sortable) myDelegate).sortAscending(); } else { //this.sortAscending(0L, this.count() - 1L); try { ForkJoinPool.commonPool().submit(new QuickAscendingSorter(this)).get(); } catch (InterruptedException | ExecutionException exception) { exception.printStackTrace(); } } }
public void sortDescending() { if ((myDelegate instanceof Mutate1D.Sortable) && (this.count() == myDelegate.count())) { ((Mutate1D.Sortable) myDelegate).sortDescending(); } else { //this.sortDescending(0L, this.count() - 1L); try { ForkJoinPool.commonPool().submit(new QuickDescendingSorter(this)).get(); } catch (InterruptedException | ExecutionException exception) { exception.printStackTrace(); } } }
public void sortDescending() { if ((myDelegate instanceof Mutate1D.Sortable) && (this.count() == myDelegate.count())) { ((Mutate1D.Sortable) myDelegate).sortDescending(); } else { //this.sortDescending(0L, this.count() - 1L); try { ForkJoinPool.commonPool().submit(new QuickDescendingSorter(this)).get(); } catch (InterruptedException | ExecutionException exception) { exception.printStackTrace(); } } }
public void sortAscending() { if ((myDelegate instanceof Mutate1D.Sortable) && (this.count() == myDelegate.count())) { ((Mutate1D.Sortable) myDelegate).sortAscending(); } else { //this.sortAscending(0L, this.count() - 1L); try { ForkJoinPool.commonPool().submit(new QuickAscendingSorter(this)).get(); } catch (InterruptedException | ExecutionException exception) { exception.printStackTrace(); } } }
@Test(expected = CPUReactiveAuditException.class) public void get_to() throws InterruptedException, ExecutionException, TimeoutException { TestTools.strict.commit(); e.get(1, TimeUnit.MILLISECONDS); }
@Test(expected = CPUReactiveAuditException.class) public void get() throws InterruptedException, ExecutionException { TestTools.strict.commit(); e.get(); }