How to keep a java program running 24/7?


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:

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:

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.

Leave a Reply