Refine search
public static ExecutorService newScalingThreadPool(final int maxThreads) { final ForkJoinPool.ForkJoinWorkerThreadFactory factory = pool -> { final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool); worker.setName("OrbitThread-" + worker.getPoolIndex()); return worker; }; return new ForkJoinPool(maxThreads, factory, (t, e) -> logger.log(Level.SEVERE, "Uncaught exception", e), false); } }
/** * 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); } } } }
wt.setDaemon(true); if ((handler = ueh) != null) wt.setUncaughtExceptionHandler(handler); do {} while (!U.compareAndSwapInt(this, INDEXSEED, s = indexSeed, s += SEED_INCREMENT) || if (((ps = plock) & PL_LOCK) != 0 || !U.compareAndSwapInt(this, PLOCK, ps, ps += PL_LOCK)) ps = acquirePlock(); int nps = (ps & SHUTDOWN) | ((ps + PL_LOCK) & ~SHUTDOWN); try { releasePlock(nps); wt.setName(workerNamePrefix.concat(Integer.toString(w.poolIndex))); return w;
@Override public ForkJoinWorkerThread newThread(ForkJoinPool pool) { final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool); worker.setName("dogged-cubing-cuboid-worker-" + worker.getPoolIndex()); return worker; } };
static ForkJoinPool setUpForkJoinPool() { int numThreads; try { String configuredNumThreads = System.getProperty("maxParallelTestThreads"); numThreads = Math.max(2, Integer.parseInt(configuredNumThreads)); } catch (Exception ignored) { Runtime runtime = Runtime.getRuntime(); numThreads = Math.max(2, runtime.availableProcessors()); } ForkJoinPool.ForkJoinWorkerThreadFactory threadFactory = pool -> { if (pool.getPoolSize() >= pool.getParallelism()) { return null; } else { ForkJoinWorkerThread thread = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool); thread.setName("JUnit-" + thread.getName()); return thread; } }; return new ForkJoinPool(numThreads, threadFactory, null, false); }
@Inject public ScheduledEmailService( @Named("ui.metadata.jdbc") JDBCPoolDataSource dataSource, LockService lockService, WebUserHttpService webUserHttpService, RakamUIConfig rakamUIConfig, EmailClientConfig emailConfig) { dbi = new DBI(dataSource); this.lockService = lockService; this.webUserHttpService = webUserHttpService; this.screenCaptureService = rakamUIConfig.getScreenCaptureService(); this.mailSender = emailConfig.getMailSender(); this.siteHost = emailConfig.getSiteUrl().getHost() + (emailConfig.getSiteUrl().getPort() == -1 ? "" : (":" + emailConfig.getSiteUrl().getPort())); this.scheduler = Executors.newScheduledThreadPool(1, new ThreadFactoryBuilder() .setNameFormat("scheduled-email-scheduler") .setUncaughtExceptionHandler((t, e) -> LOGGER.error(e)) .build()); executorService = MoreExecutors.listeningDecorator(new ForkJoinPool (Runtime.getRuntime().availableProcessors(), pool -> { ForkJoinWorkerThread forkJoinWorkerThread = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool); forkJoinWorkerThread.setName("scheduled-email-task-worker"); return forkJoinWorkerThread; }, null, true)); }
private void allocateExecutors() { if (this.executor != null) { this.executor.shutdownNow(); } if (this.scheduledExecutor != null) { this.scheduledExecutor.shutdownNow(); } if (this.serviceScheduledExecutor != null) { this.serviceScheduledExecutor.shutdownNow(); } this.executorPool = new ForkJoinPool(Utils.DEFAULT_THREAD_COUNT, (pool) -> { ForkJoinWorkerThread res = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool); res.setName(getUri() + "/" + res.getName()); return res; }, null, false); this.executor = TracingExecutor.create(this.executorPool, this.otTracer); this.scheduledExecutorPool = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool( Utils.DEFAULT_THREAD_COUNT, new NamedThreadFactory(getUri() + "/scheduled")); this.scheduledExecutor = TracingScheduledExecutor.create(this.scheduledExecutorPool, this.otTracer); this.serviceScheduledExecutor = Executors.newScheduledThreadPool( Utils.DEFAULT_THREAD_COUNT / 2, new NamedThreadFactory(getUri() + "/service-scheduled")); }
final ForkJoinWorkerThreadFactory factory = new ForkJoinWorkerThreadFactory() { @Override public ForkJoinWorkerThread newThread(ForkJoinPool pool) { final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool); worker.setName("my-thread-prefix-name-" + worker.getPoolIndex()); return worker; } }; forkJoinPool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), factory, null, false);
private static ForkJoinWorkerThreadFactory fjwtf(final String name) { AtomicLong id = new AtomicLong(); return pool -> { ForkJoinWorkerThread thread = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool); thread.setName(name + "-" + id.incrementAndGet()); return thread; }; }
/** * Tries to create and start one worker if fewer than target * parallelism level exist. Adjusts counts etc on failure. */ private void tryAddWorker() { long c; int u; while ((u = (int)((c = ctl) >>> 32)) < 0 && (u & SHORT_SIGN) != 0 && (int)c == 0) { long nc = (long)(((u + UTC_UNIT) & UTC_MASK) | ((u + UAC_UNIT) & UAC_MASK)) << 32; if (U.compareAndSwapLong(this, CTL, c, nc)) { ForkJoinWorkerThreadFactory fac; Throwable ex = null; ForkJoinWorkerThread wt = null; try { if ((fac = factory) != null && (wt = fac.newThread(this)) != null) { wt.start(); break; } } catch (Throwable e) { ex = e; } deregisterWorker(wt, ex); break; } } }
/** * Creates a ForkJoinWorkerThread operating in the given pool. * * @param pool the pool this thread works in * @throws NullPointerException if pool is null */ protected ForkJoinWorkerThread(ForkJoinPool pool) { super(pool.nextWorkerName()); this.pool = pool; int k = pool.registerWorker(this); poolIndex = k; eventCount = ~k & SMASK; // clear wait count locallyFifo = pool.locallyFifo; Thread.UncaughtExceptionHandler ueh = pool.ueh; if (ueh != null) setUncaughtExceptionHandler(ueh); setDaemon(true); }
@Override public ForkJoinWorkerThread newThread(ForkJoinPool pool) { ForkJoinWorkerThread t = new FJWT(pool); t.setName("ForkJoinScheduler(parallelism=" + size + ")-" + (++i)); t.setPriority(Thread.NORM_PRIORITY); t.setDaemon(true); return t; } }, null, 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.work(this); } catch (Throwable ex) { exception = ex; } finally { onTermination(exception); } }
@Override public ForkJoinWorkerThread newThread(ForkJoinPool pool) { ForkJoinWorkerThread thread = createThread(pool); // ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool); final String workerNumber = thread.getName().substring(thread.getName().lastIndexOf('-') + 1); final String newThreadName = "ForkJoinPool-" + name + "-worker-" + workerNumber; thread.setName(newThreadName); //thread.setUncaughtExceptionHandler(uncaughtExceptionHandler); return thread; }
/** * Tries to create and start a worker; minimally rolls back counts * on failure. */ private void addWorker() { Throwable ex = null; ForkJoinWorkerThread t = null; try { t = factory.newThread(this); } catch (Throwable e) { ex = e; } if (t == null) { // null or exceptional factory return long c; // adjust counts do {} while (!UNSAFE.compareAndSwapLong (this, ctlOffset, c = ctl, (((c - AC_UNIT) & AC_MASK) | ((c - TC_UNIT) & TC_MASK) | (c & ~(AC_MASK|TC_MASK))))); // Propagate exception if originating from an external caller if (!tryTerminate(false) && ex != null && !(Thread.currentThread() instanceof ForkJoinWorkerThread)) UNSAFE.throwException(ex); } else t.start(); }
public final ForkJoinWorkerThread newThread(ForkJoinPool pool) { return new ForkJoinWorkerThread(pool); } }
@Override protected void onTermination(final Throwable exception) { try { terminate(this, exception); } finally { super.onTermination(exception); } } };
static ForkJoinPool setUpForkJoinPool() { int numThreads; try { String configuredNumThreads = System.getProperty("maxParallelTestThreads"); numThreads = Math.max(2, Integer.parseInt(configuredNumThreads)); } catch (Exception ignored) { Runtime runtime = Runtime.getRuntime(); numThreads = Math.max(2, runtime.availableProcessors()); } ForkJoinPool.ForkJoinWorkerThreadFactory threadFactory = pool -> { if (pool.getPoolSize() >= pool.getParallelism()) { return null; } else { ForkJoinWorkerThread thread = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool); thread.setName("JUnit-" + thread.getName()); return thread; } }; return new ForkJoinPool(numThreads, threadFactory, null, false); }
@Override public ForkJoinWorkerThread newThread(ForkJoinPool pool) { final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool); worker.setName(threadPrefix + "-" + worker.getPoolIndex()); return worker; } }
@Override public ForkJoinWorkerThread newThread(ForkJoinPool pool) { // Note: The ForkJoinPool will create these threads as daemon threads. ForkJoinWorkerThread thread = new InternalForkJoinWorkerThread(pool); thread.setName(namePrefix + '-' + idx.getAndIncrement()); return thread; } }