Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disable akka.jvm-exit-on-fatal-error for actorsystem in java

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();
        }

    }

}
like image 372
Krutik Avatar asked Jan 07 '16 07:01

Krutik


1 Answers

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

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

like image 164
Gergely Bacso Avatar answered Sep 25 '22 11:09

Gergely Bacso