Do I need to re-use the same Akka ActorSystem or can I just create one every time I need one?

前端 未结 2 1569
春和景丽
春和景丽 2021-01-30 06:19

Akka 2.x requires many commands to reference an ActorSystem. So, to create an instance of an actor MyActor you might say:



        
2条回答
  •  盖世英雄少女心
    2021-01-30 07:15

    Creating an ActorSystem is very expensive, so you want to avoid creating a new one each time you need it. Also your actors should run in the same ActorSystem, unless there is a good reason for them not to. The name of the ActorSystem is also part the the path to the actors that run in it. E.g. if you create an actor in a system named MySystem it will have a path like akka://MySystem/user/$a. If you are in an actor context, you always have a reference to the ActorSystem. In an Actor you can call context.system. I don't know what akka-testkit expects, but you could take a look at the akka tests.

    So to sum it up, you should always use the same system, unless there is a good reason not to do so.

提交回复
热议问题