@Path("status") @GET @Produces(MediaType.APPLICATION_JSON) public Response getClusterStatus() throws Exception { InstanceConfig config = context.getExhibitor().getConfigManager().getConfig(); ServerList serverList = new ServerList(config.getString(StringConfigs.SERVERS_SPEC)); ClusterStatusTask task = new ClusterStatusTask(context.getExhibitor(), serverList.getSpecs()); List<ServerStatus> statuses = context.getExhibitor().getForkJoinPool().invoke(task); GenericEntity<List<ServerStatus>> entity = new GenericEntity<List<ServerStatus>>(statuses){}; return Response.ok(entity).build(); }
public void test () { Log.info("CholTest::test enter"); for (int sz = 6000; sz < 10000; sz+=2000) { Log.info("CholTest::test sz is " + sz); DataSetup data = new DataSetup(sz, 12345); long start = System.currentTimeMillis(); CholeskyDecomposition jamaChol = new Matrix(data.xx).chol(); Log.info("JAMA CHOLESKY [N = " + sz + "] TAKES " + (System.currentTimeMillis() - start) + " MILLISECONDS."); if (!jamaChol.isSPD()) continue; ForkJoinPool fjp = new ForkJoinPool(32); for (int t = 2; t <= 32; t += 2) { for (int step : STEPS) fjp.invoke(new TestSetup(new DataSetup(data.xx),jamaChol.getL().getArray(),step,t)); } } Log.info("CholTest::test exit"); }
((u + UAC_UNIT) & UAC_MASK)) << 32; if (U.compareAndSwapLong(this, CTL, c, nc)) { addWorker(); break;
/** * Initiates an orderly shutdown in which previously submitted * tasks are executed, but no new tasks will be accepted. * Invocation has no additional effect if already shut down. * Tasks that are in the process of being submitted concurrently * during the course of this method may or may not be rejected. * * @throws SecurityException if a security manager exists and * the caller is not permitted to modify threads * because it does not hold {@link * java.lang.RuntimePermission}{@code ("modifyThread")} */ public void shutdown() { checkPermission(); tryTerminate(false, true); }
/** * This method is required to be public, but should never be * called explicitly. It performs the main run loop to execute * {@link ForkJoinTask}s. */ public void run() { Throwable exception = null; try { onStart(); pool.runWorker(workQueue); } catch (Throwable ex) { exception = ex; } finally { try { onTermination(exception); } catch (Throwable ex) { if (exception == null) exception = ex; } finally { pool.deregisterWorker(this, exception); } } } }
U.compareAndSwapObject(a, i, t, null)) { if (q.top - (q.base = b + 1) > 1) signalWork(); // help pushes signal return t; idleAwaitWork(w, nc, c);
private static Future<Response> executeAndReturn(FutureTask<Response> futureTask) { forkJoinPool.execute(futureTask); return futureTask; }
/** * Creates a fork/join pool of given size. Each thread will have the uncaught exception handler set * to print the unhandled exception to standard error output. * * @param poolSize The required pool size @return The created thread pool * @return The newly created thread pool */ private static ForkJoinPool createPool(final int poolSize) { assert poolSize > 0; final Thread.UncaughtExceptionHandler uncaughtExceptionHandler = new Thread.UncaughtExceptionHandler() { @Override @SuppressWarnings({"UseOfSystemOutOrSystemErr"}) public void uncaughtException(final Thread t, final Throwable e) { System.err.println(Pool.UNCAUGHT_EXCEPTION_OCCURRED_IN_GPARS_POOL + t.getName()); e.printStackTrace(System.err); } }; return new ForkJoinPool(poolSize, ForkJoinPool.defaultForkJoinWorkerThreadFactory, uncaughtExceptionHandler, false); }
return true; // update next time if ((!shutdown || !tryTerminate(false)) && (int)c != 0 && parallelism + (int)(nc >> AC_SHIFT) == 0 && blockedCount == 0 && quiescerCount == 0) idleAwaitWork(w, nc, c, v); // quiescent for (boolean rescanned = false;;) { if (w.eventCount != v) if (u != null) { if (u.queueBase != u.queueTop && !tryReleaseWaiter()) rescanned = false; // contended if (w.eventCount != v) (queueBase != queueTop && !tryReleaseWaiter())) rescanned = false; if (!rescanned)
@Override public ForkJoinWorkerThread newThread(ForkJoinPool pool) { int cap = 4 * NUMCPUS; return pool.getPoolSize() <= cap ? new FJWThr(pool) : null; } }
/** * Tries to create and start a worker */ private void addWorker() { Throwable ex = null; ForkJoinWorkerThread wt = null; try { if ((wt = factory.newThread(this)) != null) { wt.start(); return; } } catch (Throwable e) { ex = e; } deregisterWorker(wt, ex); // adjust counts etc on failure }
Thread.UncaughtExceptionHandler handler, boolean asyncMode) { checkPermission(); if (factory == null) throw new NullPointerException();
/** * Returns size threshold for splitting into subtask. By * default, uses about 8 times as many tasks as threads */ final int computeThreshold() { int n = fence - origin; int p = ex.getParallelism(); return threshold = (p > 1) ? (1 + n / (p << 3)) : n; }
private static Future<Response> executeAndReturn(FutureTask<Response> futureTask) { forkJoinPool.execute(futureTask); return futureTask; }
/** * Attempts to cancel and/or stop all tasks, and reject all * subsequently submitted tasks. Tasks that are in the process of * being submitted or executed concurrently during the course of * this method may or may not be rejected. This method cancels * both existing and unexecuted tasks, in order to permit * termination in the presence of task dependencies. So the method * always returns an empty list (unlike the case for some other * Executors). * * @return an empty list * @throws SecurityException if a security manager exists and * the caller is not permitted to modify threads * because it does not hold {@link * java.lang.RuntimePermission}{@code ("modifyThread")} */ public List<Runnable> shutdownNow() { checkPermission(); tryTerminate(true, true); return Collections.emptyList(); }
static ForkJoinPool defaultExecutor() { ForkJoinPool p = defaultExecutor; // double-check if (p == null) { synchronized (poolLock) { p = defaultExecutor; if (p == null) { // use ceil(7/8 * ncpus) int nprocs = Runtime.getRuntime().availableProcessors(); int nthreads = nprocs - (nprocs >>> 3); defaultExecutor = p = new ForkJoinPool(nthreads); } } } return p; }
/** * Creates the pool wrapping the provided ForkJoinPool * * @param pool The ForkJoinPool instance to wrap */ public FJPool(final ForkJoinPool pool) { this.pool = pool; this.configuredPoolSize = pool.getPoolSize(); }
/** * Performs cleanup associated with termination of this worker * thread. If you override this method, you must invoke * {@code super.onTermination} at the end of the overridden method. * * @param exception the exception causing this thread to abort due * to an unrecoverable error, or {@code null} if completed normally */ protected void onTermination(Throwable exception) { try { terminate = true; cancelTasks(); pool.deregisterWorker(this, exception); } catch (Throwable ex) { // Shouldn't ever happen if (exception == null) // but if so, at least rethrown exception = ex; } finally { if (exception != null) UNSAFE.throwException(exception); } }
Thread.UncaughtExceptionHandler handler, boolean asyncMode) { checkPermission(); if (factory == null) throw new NullPointerException();
/** * Returns size threshold for splitting into subtask. By * default, uses about 8 times as many tasks as threads */ final int computeThreshold() { int n = fence - origin; int p = ex.getParallelism(); return threshold = (p > 1) ? (1 + n / (p << 3)) : n; }