What's the difference of the Akka's Actor with Scala's Actor model

ScalaActorAkka

Scala Problem Overview


I found there is also an Akka actor model, so I am wondering what's the difference between the Akka's Actor and Scala's Actor model?

Scala Solutions


Solution 1 - Scala

Well, there isn't. There is just Actor model, and Akka actors and Scala actors are two implementations of that model.

All Actor model says that your concurrency primitives are actors, which can:

  • receive a message and decide what to do next depending on the content of the message, including:

  • send messages to any actors they know about

  • create new actors

and provides certain guarantees, e.g.:

  • any actor will only handle a single message at a time

  • messages sent by actor X to actor Y will arrive in the order thay were sent

There is no difference between Scala and Akka actors on this level.

For differences in what they can do, see https://stackoverflow.com/questions/2906162/different-scala-actor-implementations-overview. The biggest one, for me, is that Akka supports supervisors and ActorRegistry.

Solution 2 - Scala

There is also a historical answer. The creators of Scala thought there should be an actor framework. Jonas Bonér tried it out, but was not completely satisfied so he started working on a new - which evolved into Akka. However, the Scala people thought it was better than their own - so at Jfokus 2011 they announced that Akka was to become the standard actor framework of Scala. However, that migration will take some time.

Solution 3 - Scala

This depends a little on what you mean with "model" - you can either refer to the "execution model" or the "programming model" (and perhaps other models as well).

For execution models, there are basically two: thread-based or event-based. The Scala standard actor library contains both. The thread-based uses one thread for each actor, whereas the event-based uses a thread-pool. The former is more intuitive to understand, the latter is more efficient. Akka is built on the event-based model.

For programming model, there is a big difference between the scala standard library and Akka. In the scala standard library, you basically implement the "run" method - and if you want to wait for an incoming message, you get yourself into a waiting state (by calling "receive" or "react"). So, the programming model follow the "thread-metaphor". However, in Akka, the programming metaphor is that you implement a few life-cycle methods - but the "run"-method is written inside the framework. It actually turns out that this programming model works a lot better with the event-based execution model as well.

If you are interested in the different execution models and programming models of scala standard actors I have written a few posts on the issue.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEvans Y.View Question on Stackoverflow
Solution 1 - ScalaAlexey RomanovView Answer on Stackoverflow
Solution 2 - ScalaDan Bergh JohnssonView Answer on Stackoverflow
Solution 3 - ScalaDan Bergh JohnssonView Answer on Stackoverflow