Search code examples
javascalaakkaactor

Akka: Should I use parallelStream or executors in an actor


I am new to Akka actor model. As I understand, akka provides abstraction over parallelism and concurrency. Having said that, I don't feel it's right to have concurrency via parallelStream or executor framework in an actor itself, wanted to know if this is an anti-pattern. Also, does that mean all code in an actor would be sequential always ?


Solution

  • If you refer to the parallel streams of Java itself, then "likely not". Especially as most of the "get results" operations on those are blocking, so you'd be forced to block in the Actor, which indeed is an anti-pattern (read here about it: blocking needs careful management).

    You can however use Akka Streams inside Actors more freely, this is because all of their operations offload the work to a separate dispatcher, so it won't block the Actor. They're also more configurable and offer connectors to various tech, and integrate well Actors themselves.