什么时候可以安全地阻止Akka 2演员?

编程入门 行业动态 更新时间:2024-10-07 06:39:30
本文介绍了什么时候可以安全地阻止Akka 2演员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我知道不建议您阻塞演员的 receive 方法,但是我相信可以做到(只要也不要这样做)

I know that it is not recommended to block in the receive method of an actor, but I believe it can be done (as long as it is not done in too many actors at once).

这篇文章建议阻止 preStart 作为解决问题的一种方法,因此大概阻止 preStart 是安全的。

This post suggests blocking in preStart as one way to solve a problem, so presumably blocking in preStart is safe.

但是,我尝试阻止 preRestart (不是 preStart ),一切似乎都死机了-不再记录接收到的消息。

However, I tried to block in preRestart (not preStart) and everything seemed to just hang - no more messages were logged as received.

此外,在无法安全阻止的情况下,是一个安全的选择吗?

Also, in cases where it is not safe to block, what is a safe alternative?

推荐答案

从不阻止演员。

如果您的actor是actor层次结构的一部分(应该如此),那么actor系统将无法停止它。 演员的生命周期(监督,监视等)是通过消息传递完成的。 停止阻止儿童的父演员是行不通的。

If your actor is part of an actor hierarchy (and it should be), the actor system is not able to stop it. The actor's life-cycle (supervision, watchig etc.) is done by messaging. Stopping a parent actor of a blocking child will not work.

也许有多种方法可以将阻止条件与演员的生命周期结合起来。 但这会导致复杂性和风格失调。

Maybe there are ways to couple the blocking condition with the actor's lifecycle. But this would lead to overload of complications and bad-style.

因此,最好的方法是在该演员外部进行遮挡。 例如您可以通过执行程序服务在单独的线程中运行阻止代码。

So, the best way is to do the blocking part outside of that actor. E.g. you could run the blocking code via an executor service in a separate thread.

更多推荐

什么时候可以安全地阻止Akka 2演员?

本文发布于:2023-11-25 06:16:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628643.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:什么时候   演员   Akka

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!