Ubuntu – Tomcat on virtual server: JVM cannot start because 44 GB Ram is not enough

javamemorytomcatUbuntuvirtual-machines

I'm renting a virtual machine, running Ubuntu 9.04. I installed the SUN JDK 6.0 (via apt-get) and Tomcat 6.0.18 (via unzipping).

General problem with Java (partly solved)

At first, it was impossible to run a JVM because of memory problems. Even something simple as java -version failed with

Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.

I figured out that even though free reported 44 GB of free memory, I was only allowed to use a small fraction of it, something like 284 MB per allocation. Running java -Xms10m -Xmx256m -version works fine, but I don't want to change every script that invokes java.

Also I read about the JAVA_OPTS environment variable, which is honored by many apps. I've set this to "-Xms10m -Xmx256m"

Problem with Tomcat

The tomcat startup script catalina.sh also uses JAVA_OPTS. But event though, I still get the three error lines mentioned above, readable in logs/catalina.out. I know that JAVA_OPTS is used, because when I put nonsense into that variable, I see the consequences in logs/catalina.out.

It seems like Tomcat also wants to start javac, which needs the options prefixed with -J like -J-Xms10m -J-Xmx256m instead. But I'm not sure if this is related to the problem, because there is no more output than those three lines.

I'm starting Tomcat via bin/startup.sh which in turn calls bin/catalina.sh. I know there is also the possibilty to start it via jsrv, but I cannot do this, because the make / configure process for jsrv also wants to call javac which fails with the well known three line error message mentioned above.

Now I'd be interested in two possible kinds of solution:

  • how can I make Java just work on my virtual host, no matter who calls java or javac and no matter how he calls it?
  • if this is impossible, how can I adjust Tomcat to just run?

PS: Please note that I only have control over the virtual machine, but no control and only limited knowledge over/about the surrounding physical machine.

PPS: Sorry for the noobish title of this question, but I felt that the original, well written title did not attract enough readers, so I thought this might help 😉 It actually helped, as I got 0 views in the first hour, but 8 views in the hour after the change. Strange world.

Edit: this is the output of ulimit -a:

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 20
file size               (blocks, -f) unlimited
pending signals                 (-i) 16382
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) unlimited
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

Best Answer

javac generally spawns a separate process which should fall underneath different process rules.

-J options are for passing args via a wrapper/launcher to the JVM, I've not seen this on Tomcat.

Find out where the -Xmx is coming from:

find /your/install/dir/with/tomcat |xargs grep '-Xmx'