Recover / Restart java daemon from failure

I am running a java application as a daemon on a Linux machine using a custom shell script.

Since I am new to java and linux, I want to know if it is possible that the application itself resurrects itself (like restarting) and recovers from cases such as application crashes, unhandled exceptions or from memory, etc.

early

Ashish Sharma

+3
source share
5 answers

The JVM is designed to die when there is a fatal error. The ones you described fall into this category.

, , script Python script, , , , . Unix "pgrep" , , JVM (, , ). , , JVM .

, , , , , . , , , , .

+3

Wrappers, , Java Wrapper (, Community Edition ist GPL) ,

+3

unix "inittab" . , . (Respawn)

+2

, - , , ; , , , , , , / , , ( , / , , , ).

, , , (, , , , , , , , "" ).

, , , " , " ( , , - "ps -blahblah" ), java "while true" :

while true
do
  # launch the java program here, no background
  # when crashing, the shell will be given hand back
  java -classpath blahblah...
  echo "program crashed, relaunching it..."
done
+2

I'm not sure if the application itself can handle such crashes. You can write a script shell in linux that can work as a cron job to control the application, checking if the java application is running on schedule, and if not, it will automatically restart it.

+1
source

Source: https://habr.com/ru/post/1739156/


All Articles