Quantcast
Channel: Akka Libraries - Discussion Forum for Akka technologies
Viewing all articles
Browse latest Browse all 1365

Why no reuse of `Behavior` enclosing class?

$
0
0

@ignatius wrote:

Just getting my hands dirty with Akka Typed. In the docs of this heading, under the third code-block, it says,

That’s nice. One thing to be cautious with here is that it’s important that you create a new instance for each spawned actor, since those parameters must not be shared between different actor instances.

As I understand it, this sentence is referring to the Counter class which contains a factory method for a Behavior, and when it refers to “those parameters” it means the fields of the Counter class must not be shared by multiple actors (behaviors). The Counter class itself is not a Behavior, it only contains a factory method.

Why can’t I reuse the class instance, if the parameters of the Counter class are immutable? It is my understanding that this should be (thread-)safe and I have the liberty to do so. Is this a style recommendation, maybe to prevent accidentally shared mutable state, or is it a technical requirement?

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 1365

Trending Articles