DevilKing's blog

冷灯看剑,剑上几分功名?炉香无需计苍生,纵一穿烟逝,万丈云埋,孤阳还照古陵

0%

akka best practices

原文链接

  • Don’t share mutable state among actors
  • Do not close on the sender
  • Do not close over an actor’s context
  • Do not use the scheduler with the Runnable trait
  • Actors do not stop automatically when no longer referenced, every Actor that is created must also explicitly be destroyed. The only simplification is that stopping a parent Actor will also recursively stop all the child Actors that this parent has created.
  • It is always preferable to communicate with other Actors using their ActorRef instead of relying upon ActorSelection. Exceptions are
    • sending messages using the At-Least-Once Delivery facility
      • initiating first contact with a remote system
      • In all other cases ActorRefs can be provided during Actor creation or initialization, passing them from parent to child or introducing Actors by sending their ActorRefs to other Actors within messages.
  • Messages can be any kind of object but have to be immutable
  • Always prefer tell for performance, and only ask if you must.
  • To complete the future with an exception you need send a Failure message to the sender. This is not done automatically when an actor throws an exception while processing a message.
  • Set the number of thread in the pool to match your cores

关于actor的close部分?

关于mutable state的定义部分