Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set default maximum heap size for Java (xmx), for linux (centos)

I have many small java programs running in crons in my server. I have an openvz VPS, and java is very poblematic with memory and openvz.

The best solution i have come up so far is running my programs with:

java -Xmx16m class

This works ok, but I have many programs running, and i want to set the default maximum heap for all the system, so that i don't change all the start up scripts, and not have to remember to do that every time i write a new one.

I tried finding a way to set/change a global default value for my CentOS system, but i had no luck with that!

I would appreciate if someone could help me.

Thanks.

like image 406
Nikos Avatar asked Dec 03 '22 08:12

Nikos


2 Answers

You could try adding this to your shell profile export _JAVA_OPTIONS=-Xmx16m

This may or may not work depending on what JVM you are running.

like image 121
Jon Avatar answered Dec 06 '22 10:12

Jon


Create an environment variable _JAVA_OPTIONS and set the new value there. That should work

like image 37
OscarRyz Avatar answered Dec 06 '22 09:12

OscarRyz