It looks like you need to use the future . As far as I understand, Akka futures care about creating and destroying actors for you; if you flatMap
several futures together, you will notice that some are executed inside the same actor, and for others a new one is created. Shamelessly rephrase the documentation:
import akka.japi.Function; import java.util.concurrent.Callable; import akka.dispatch.Futures; import akka.dispatch.OnComplete; Future<String> f = Futures.future(new Callable<String>() { public String call() { return "Hello" + "World"; } }, system.dispatcher()).andThen(new OnComplete<String>() { public void onComplete(Throwable err, String result) {
I think something like this might be enough? See the document for more examples ...
@viktor-clang may know differently about this, but I donβt think you are particularly worried about the number of actors generated in the general case; they are much cheaper to create than OS threads.
source share