Sometimes is usefull to limit the maximum heap size for java. (Especially in a OpenVZ virtual machine(VPS) where java memory managment is terrible: can do this with the xmx parametr of command line java, but if you run many programs, with crons and through other programs, you will need a way to globaly set that (and any other java command line argument).

To set this globally, you must add something to the .bashrc file.

vi ~/.bashrc

and add:

export _JAVA_OPTIONS=-Xmx16m

You see that you can easily add any more parametrs you want (xms classpath etc)

That will take care whenever you manually start a java program. But if you run them with crons (like me) this won’t work. You have to add it to your cron file

crontab -e

and add the line:


That’s it. Thanks