Don't provide executor by default

This commit is contained in:
DBotThePony 2024-02-14 12:26:04 +07:00
parent 4972bea1ce
commit 021b991ab5
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -6,12 +6,9 @@ import java.util.concurrent.ConcurrentLinkedQueue
import java.util.concurrent.ExecutionException
import java.util.concurrent.Executor
import java.util.concurrent.ExecutorService
import java.util.concurrent.ForkJoinPool
import java.util.concurrent.Future
import java.util.concurrent.FutureTask
import java.util.concurrent.RejectedExecutionException
import java.util.concurrent.SynchronousQueue
import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.locks.LockSupport
@ -23,8 +20,6 @@ import java.util.concurrent.locks.LockSupport
* [CarriedExecutor], since when they are done, they unmount themselves from [parentExecutor], allowing thread to perform other work
*/
class CarriedExecutor(private val parentExecutor: Executor) : Runnable, ExecutorService {
constructor() : this(ASYNC_POOL)
private val isCarried = AtomicBoolean()
private val queue = ConcurrentLinkedQueue<Runnable>()
private val isShutdown = AtomicBoolean()
@ -189,13 +184,4 @@ class CarriedExecutor(private val parentExecutor: Executor) : Runnable, Executor
return
}
}
companion object {
/**
* Default executor -- ForkJoinPool.commonPool() unless it cannot
* support parallelism.
*/
private val ASYNC_POOL: Executor =
if (ForkJoinPool.getCommonPoolParallelism() > 1) ForkJoinPool.commonPool() else ThreadPoolExecutor(0, Int.MAX_VALUE, 10L, TimeUnit.SECONDS, SynchronousQueue())
}
}