Reputation: 715
I am using Akka. I am trying to work out how to bind a set of actors (in the thousands) so that each unique actor is handled by the same thread. For example, my OS has 24 native threads, I have 1000 actors each handling a unique piece of data: d1, d2, d3, .. dn and I always want d1 to be handled by the same thread 1. In Java I would pre-allocate 24 threads and maintain a map of ids to threads, allocating them in a round robin fashion. Example: 2 threads, 5 data d1,d3, d5 th1 d2, d4 th2
I have looked at the Akka documentation and out of the 4 dispatchers, none meet my needs. The closest one is PinnedDispatcher - but it keeps creating native threads and the result is an OOME.
Any idea about this apart from the creation of my own Dispatcher?
Thank you
Upvotes: 1
Views: 448
Reputation: 26597
You don't need to create your own dispatcher, you only need to create your own ExecutorService that you provide to any dispatcher using a ExecutorServiceConfigurator so that when the actor is scheduled to be executed you send it to "its" Thread. You could essentially keep a map of single-threaded ExecutorServices
Hope that helps!
Cheers, √
Upvotes: 3