DP_ DP_ - 7 months ago 68
Java Question

How to run a Java console application all the time?

I have a server (Ubuntu 14.04.4 LTS) and want a certain Java application to run on it all the time. Currently I start it using

nohup gradle run &
. Yesterday it stopped working.
shows the following error message:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':run'.
> Process 'command '/usr/lib/jvm/java-8-oracle/bin/java'' finished with non-zero exit value 137

How do I need to change my Java application to prevent such errors in future (make sure that the application runs all the time and -- ideally -- is restarted automatically, if it crashes) ? I'm looking for simple, minimal solutions.

Note that I had similar issues on servers of this particular company before. I had an Apache server with a web application and sometimes it would stop working for no apparent reason (maybe the server was put to sleep because of low activity, no idea).


As said in comments it is an Out Of Memory Exception, you can do:

Rewiev you code, maybe you can have low performances in your code.

If you are running a simple "java application" you can, instead click "Run As.. Java Application" click "Run As.. Run Configration", select your java application and in TAB "Arguments", "VM Arguments" add this parameters:

-Xmx1024m -Xms512m 

with this parameters you allocate a minimum of 512M on your application (at the start) and a maximum of 1024M. You can enlarge this numbers as needed.