private static Future<Response> executeAndReturn(FutureTask<Response> futureTask) { forkJoinPool.execute(futureTask); return futureTask; }
private static Future<Response> executeAndReturn(FutureTask<Response> futureTask) { forkJoinPool.execute(futureTask); return futureTask; }
private static Future<Response> executeAndReturn(FutureTask<Response> futureTask) { forkJoinPool.execute(futureTask); return futureTask; }
/** * Evaluates an expression asynchronously. */ public static void spawn(final VoidFunction0 p) { forkJoinPool.execute(new Runnable() { public void run() { try { p.apply(); } catch (Throwable t) { logger.log(Level.WARNING, "Exception is thrown on a spawn thread.", t); } } }); }
/** * [Original] Converts to {@link java.util.concurrent.Future} */ public Future<R> toJucFuture() { final RichFunction0<R> _this = this; FutureTask<R> future = new FutureTask<R>(new Callable<R>() { public R call() throws Exception { return _this.apply(); } }); forkJoinPool.execute(future); return future; }
/** * Evaluates an expression asynchronously, and returns a closure for * retrieving the result. */ public static <R> Future<R> future(final Function0<R> p) { final FutureTask<R> future = new FutureTask<R>(new Callable<R>() { public R call() throws Exception { return p.apply(); } }); forkJoinPool.execute(future); return future; }
/** * Evaluates two expressions in parallel. */ public static <A, B> Tuple2<A, B> par(final Function0<A> xp, final Function0<B> yp) throws InterruptedException, ExecutionException { final FutureTask<A> xpFuture = new FutureTask<A>(new Callable<A>() { public A call() throws Exception { return xp.apply(); } }); final FutureTask<B> ypFuture = new FutureTask<B>(new Callable<B>() { public B call() throws Exception { return yp.apply(); } }); forkJoinPool.execute(xpFuture); forkJoinPool.execute(ypFuture); return Tuple.apply(xpFuture.get(), ypFuture.get()); }
@Override public void foreach(final VoidFunction1<T> f) { if (isEmpty()) { NIL.foreach(f); return; } for (final T element : collection) { forkJoinPool.execute(new Runnable() { public void run() { try { f.apply(element); } catch (Throwable t) { logger.log(Level.WARNING, "Exception is thrown on a spawn thread.", t); } } }); } }