?: getOrCreatePoolSync() @Volatile private var pool: Executor? = null @Synchronized private fun getOrCreatePoolSync(): Executor = pool ?: createPool().also { pool = it } private fun createPool(): ExecutorService { if (System.getSecurityManager() != null) return createPlainPool() // Reflection on ForkJoinPool class so that it works on JDK 6 (which is absent there) val fjpClass = Try { Class.forName("java.util.concurrent.ForkJoinPool") } ?: return createPlainPool() // Fallback to plain thread pool // Try to use commonPool unless parallelism was explicitly specified or in debug privatePool mode if (!usePrivatePool && requestedParallelism < 0) { Try { fjpClass.getMethod("commonPool")?.invoke(null) as? ExecutorService } ?.takeIf { isGoodCommonPool(fjpClass, it) } ?.let { return it } } // Try to create private ForkJoinPool instance Try { fjpClass.getConstructor(Int::class.java).newInstance(parallelism) as? ExecutorService } ?. let { return it } // Fallback to plain thread pool return createPlainPool() } pool͕nullͳΒCreatePoolSyncΛ࡞Δ pool͕nullͳΒCreatePool createPlainPool͢ΔͱExecutorServiceΛ࡞Δ