I made a Java program and made it a jar file. I want to make it running 24/7 on my AWS. I use an application called screen to keep it running after I log out. I use this command:
screen java -jar my_app.jar
But it cannot keep running all the time. It happens to stop after running for one or two days. I made keep a log, and I didn't find any exception to terminate it. I wonder if the JVM will kill my application for any reason, such as high memory usage? Does the JVM keep a log? Where can I find the log of JVM? Do I have to make my app a deamon ? If I have to, how?
No, there's nothing special to keep a Java app running. Just have at least one non-daemon thread still active. For instance, this is a complete program that would run forever:
public class Forever {
public static void main(String[] args) throws InterruptedException {
while (true) { Thread.sleep(1000); }
}
}
If your app is dying, it's because of some error somewhere. Make sure to inspect whatever logs are being written and the stdout and stderr of the process to find the cause.
maybe you found a solution, but on windows, you can use a batch "watchdog" to re-launch your program when it closes (and also log data).
:launch
java -jar my_app.jar 1>>log.txt 2>>err.txt
goto launch
on linux/unix you can make a bash along those lines (I'm too lazy to do a 2 min search) also, a good thing would be to monitor your app's memory usage, and close it if it is over a threshold (like 70%), it will be re-launched by the ba*h script
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With