Linux – java program out of memory before reaching xmx

javalinuxmemoryredhat

On a Redhat CentOS 6.4 are only a few process running, using about 3GB RAM (System has 12GB available). One of the processes is a WSO2ESB Server (java), we start it with those parameters:

 -Xms2048m -Xmx3072m

After a while we get an OutOfMemory Exception, but the java process(WSO2ESB) process is not even using its 3GB. In the jconsole you can also see that those parameters where set correctly (Linux Server has about 9GB free RAM at this point)

Does Linux not give us the configured 3 GByte RAM?

On a exactly same Windows Installation – the java process can use it's 3GB Ram without any issue.

enter image description here
Screenshot of the jconsole showing the heap memory usage only between 0.3 and 1.0 GB. At moment of OutOfMemory exception Heap memory was at 0.5GB, but the process would have 3GB to work with, but it doesn't…

EDIT: added log of java process:

java.lang.OutOfMemoryError: unable to create new native thread

EDIT2: added free -m output:
enter image description here

Best Answer

I solved the problem. wso2esb was using over 1000 Threads. But on linux the default amout of Threads a user can use is set to 1024. I had to rise the limit for my user, now everything works fine.

To do so: open /etc/security/limits.conf and add following two lines for your user:

myuser             soft    nproc           8192
myuser             hard    nproc           8192

enter image description here