Use case for Akka PoisonPill

孤街醉人 提交于 2019-12-25 15:50:20

问题


According to the Akka docs for PoisonPill:

You can also send an actor the akka.actor.PoisonPill message, which will stop the actor when the message is processed. PoisonPill is enqueued as ordinary messages and will be handled after messages that were already queued in the mailbox.

Although the usefulness/utility of such a feature may be obvious to an Akka Guru, to a newcomer, this sounds completely useless/reckless/dangerous.

So I ask: What's the point of this message and when would one ever use it, for any reason?!?


回答1:


We use a pattern called disposable actors:

  • A new temporary actor is created for each application request.
  • This actor may create some other actors to do some work related to the request.
  • Processed result is sent back to client.
  • All temporary actors related to this request are killed. That's the place where PoisonPill is used.

Creating an actor implies a very low overhead (about 300 bytes of RAM), so it's quite a good practise.



来源:https://stackoverflow.com/questions/30633682/use-case-for-akka-poisonpill

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!