@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; }
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); }
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); }
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")); }