I want to have fixed thread pool with once created threads. So, I create own ExecutorServiceConfigurator
:
class FixedThreadPoolExecutorServiceConfigurator(config: Config, prerequisites: DispatcherPrerequisites) extends ExecutorServiceConfigurator(config, prerequisites) {
class ThreadPoolExecutorServiceFactory extends ExecutorServiceFactory {
def createExecutorService: ExecutorService = {
Executors.newFixedThreadPool(40)
}
}
private val executor = new ThreadPoolExecutorServiceFactory()
override def createExecutorServiceFactory(id: String, threadFactory: ThreadFactory): ExecutorServiceFactory = {
executor
}
}
And used it:
blocking-dispatcher {
type = Dispatcher
executor = "abc.FixedThreadPoolExecutorServiceConfigurator"
throughput = 1
thread-pool-executor {
fixed-pool-size = 60
}
}
But every time, when my program has no any tasks, Akka shutdowns ExecutorService:
akka.dispatch.MessageDispatcher:
private val shutdownAction = new Runnable {
@tailrec
final def run(): Unit = {
shutdownSchedule match {
case SCHEDULED ⇒
try {
if (inhabitants == 0) shutdown() //Warning, racy
}
//////
}
}
}
I cannot understand this behavior. I think, that creation of threads is expensive operation.