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?