在Java中为actorsystem禁用akka.jvm

编程入门 行业动态 更新时间:2024-10-08 07:34:11
本文介绍了在Java中为actorsystem禁用akka.jvm-exit-on-fatal-error的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用akka actor系统进行多线程处理.在正常的用例中,它运行良好.但是,Akka将在发生致命错误时关闭JVM.请让我知道如何配置Akka以禁用Java中的"akka.jvm-exit-on-fatal-error".下面是代码.

I am using akka actor system for multi threading. It is working fine in normal use-cases. However, Akka is closing JVM on fatal error. Please let me know how I can configure Akka to disable "akka.jvm-exit-on-fatal-error" in java. Below is code.

public class QueueListener implements MessageListener { private String _queueName=null; public static boolean isActorinit=false; public static ActorSystem system=null; private ActorRef myActor; public QueueListener(String actorId, String qName){ this._queueName = qName; if(!isActorinit){ system=ActorSystem.create(actorId); isActorinit=true; } myActor=system.actorOf( Props.create(MessageExecutor.class, qName),qName+"id"); } /* * (non-Javadoc) * @see javax.jms.MessageListener#onMessage(javax.jms.Message) */ @Override public void onMessage(Message msg) { executeRequest(msg); } /** This method will process the message fetch by the listener. * * @param msg - javax.jms.Messages parameter get queue message */ private void executeRequest(Message msg){ String requestData=null; try { if(msg instanceof TextMessage){ TextMessage textMessage= (TextMessage) msg; requestData = textMessage.getText().toString(); }else if(msg instanceof ObjectMessage){ ObjectMessage objMsg = (ObjectMessage) msg; requestData = objMsg.getObject().toString(); } myActor.tell(requestData, ActorRef.noSender()); } catch (JMSException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }

推荐答案

在项目中创建一个application.conf文件(例如,sr/main/resources)并添加以下内容:

Create an application.conf file in your project (sr/main/resources for example) and add the following content:

akka { jvm-exit-on-fatal-error = false }

如果您已经拥有一个配置文件,则无需创建新的配置文件,在这种情况下,只需添加新条目:

No need to create new config file if you already have one of course, in that case it is just adding the new entry:

jvm-exit-on-fatal-error = false

请小心.让JVM在诸如OutOfMemory之类的致命错误之后运行通常不是一个好主意,并且会导致严重的问题.

Be careful. Letting the JVM run after fatal errors like OutOfMemory is normally not a good idea and leads to serious problems.

更多推荐

在Java中为actorsystem禁用akka.jvm

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

发布评论

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

>www.elefans.com

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