简体   繁体   English

紧急停止Akka演员

[英]Emergency stopping of Akka Actor

I am using Akka framework to control hardware, and in rare cases I need to freeze an actor in a middle of computation. 我正在使用Akka框架来控制硬件,在极少数情况下,我需要在计算中间冻结一个actor。 This prevents damage to the hardware. 这可以防止损坏硬件。 Is there a way of quickly freezing or killing and Actor, even if it is still running a task? 有没有办法快速冻结或杀死和Actor,即使它还在运行任务?

Sadly this is not something that the JVM supports. 遗憾的是,这不是JVM支持的。 While a Thread is running, for example doing some long running operation, it can not be arbitrarily interrupted (yes, there is a interrupt() call however it just sets a flag, and the Thread's user-land code may look at this flag, it's not a forceful interruption). 当Thread正在运行时,例如做一些长时间运行的操作,它不能被任意中断(是的,有一个interrupt()调用,但是它只是设置一个标志,而Thread的用户域代码可能会看到这个标志,这不是一个有力的中断)。 Since Akka Actors utilise Java threads, the same limitation applies to them. 由于Akka Actors使用Java线程,因此同样的限制适用于它们。

How Actors do help here however is that you can chunk up the work into very small chunks of work, think "steps", and represent them as messages. 然而,演员如何在这里提供帮助的是,您可以将作品分成很小的工作块,思考“步骤”,并将它们表示为消息。 If you detect you should not proceed further, you simply could stash the messages (or simply no-op on them, instead of performing some action). 如果你发现你不应该继续下去,你只需要隐藏消息(或者只是对它们进行无操作,而不是执行某些操作)。

It kind of depends what you mean by "freeze". 这有点取决于你所说的“冻结”。 By itself it's not possible, but maybe a very similar effect is achievable? 它本身是不可能的,但也许可以达到非常相似的效果?

// The killing part can be done via context stop self inside the Actor or by sending a PoisonPill , this however is asynchronous and goes through the Actors mailbox - as everything in actor communication. //杀戮部分可以通过Actor内部的context stop self或通过发送PoisonPill ,但这是异步的并且通过Actors邮箱 - 作为actor通信中的所有内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM