pedroct92 pedroct92 - 1 month ago 30
Java Question

How to limit the number of running tasks on akka scheduler?

I have an application in Java Play Framework and the user can run multiple tasks at the same time and it can take a long time to finish. I thought that I could used the

actorSystem.scheduler()
in order to do that. However, I've made a few tests and found out that the user can run up to 4 tasks at the same time otherwise the tasks would be taking more resources than my server could provide. So Is there a way to limit the number of tasks running at the same time on the Akka scheduler?

Answer

If you want to globally limit the concurrent tasks, you could set the akka max pool size to that number. Information about configuration is available here: https://playframework.com/documentation/2.5.x/JavaAkka

Specifically, there is a setting:

akka.actor.default-dispatcher.fork-join-executor.pool-size-max = 64

which you can set to the maximum number of tasks you want to run concurrently. This is the number of threads that will be used.