在Java中为actorsystem禁用akka.jvm-exit-on-fatal-error [英] disable akka.jvm-exit-on-fatal-error for actorsystem in java

查看:387
本文介绍了在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-exit-on-fatal-error的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆