protected static void initializeCommonPool_JDK8OrEarlier() { /* "common" and "commonParallelism" have to be set together. */ /* * This is a simplified version of ForkJoinPool.makeCommonPool(), without the dynamic * class loading for factory and handler based on system properties. */ int parallelism = Runtime.getRuntime().availableProcessors() - 1; if (!SubstrateOptions.MultiThreaded.getValue()) { /* * Using "parallelism = 0" gets me a ForkJoinPool that does not try to start any * threads, which is what I want if I am not multi-threaded. */ parallelism = 0; } if (parallelism > MAX_CAP) { parallelism = MAX_CAP; } final Target_java_util_concurrent_ForkJoinPool proposedPool = new Target_java_util_concurrent_ForkJoinPool(parallelism, defaultForkJoinWorkerThreadFactory, null, LIFO_QUEUE, "ForkJoinPool.commonPool-worker-"); /* The assignment to "injectedCommon" is atomic to prevent races. */ injectedCommon.compareAndSet(null, proposedPool); final ForkJoinPool actualPool = Util_java_util_concurrent_ForkJoinPool.as_ForkJoinPool(injectedCommon.get()); /* * The assignment to "commonParallelism" can race because multiple assignments are * idempotent once "injectedCommon" is set. This code is a copy of the relevant part of * the static initialization block in ForkJoinPool. */ commonParallelism = actualPool.getParallelism(); }
/** The get access method for ForkJoinPool.common. */ public static ForkJoinPool getCommon() { ensureCommonPoolIsInitialized(); return Util_java_util_concurrent_ForkJoinPool.as_ForkJoinPool(injectedCommon.get()); }