且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将参数传递给Scala对象

更新时间:2022-12-14 09:34:52

您不应在actor之外共享任何与actor相关的状态。具体来说,您不应该共享特定于Akka的变量,例如上下文,自我等。

You should not share any actor related state outside actor. Specifically you should not share akka-specific variables like context, self, etc.

仅应创建儿童演员从父母里面!从父 preStart (了解参与者生命周期)

Child actors should be created only from inside parent! It could be reasonable to initialize them from parent preStart (read about actors lifecycle)

初始化它们是合理的。 actor ref具有静态常量,请在对象中添加 child:AtomicReference [ActorRef] 并从父actor进行设置。

If you need so much direct actor ref available in static constant, add child: AtomicReference[ActorRef] in your object and set it from parent actor.