我正在使用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
发布评论