Pages

Showing posts with label JVM. Show all posts
Showing posts with label JVM. Show all posts

Friday, July 20, 2012

OutOfMemoryError: Unable to create new native thread

This post suggests how to fix OutOfMemmory (OOM) error with Java on Linux. There are 2 things to try:


[1] Reduce the stack size in JVM command line and for Linux. RHEL/Oracle Linux default is 8096k to 10240k, while even for most enterprise applications as low as 128k may suffice. HotSpot JDK7 seems to suggest a minimum of 160k. So:
  • Add "-Xss160k" to the JVM commandline
  • Set "ulimit -s 160" from the Linux shell and confirm with "ulimit -a". This setting is per user session. To make it persist for a user, add it to /etc/security/limits.conf
[2] Track the total number of threads on the system:

watch 'ps -efL|wc -l'

Check the system limit:

cat /proc/sys/kernel/pid_max # Usually 32768

If the total number of threads reaches this pid_max, JVM will throw OOM with unable to create new native threads error. 

To fix this issue:

  • Increase the system limit as root:
    echo 65536 > /proc/sys/kernel/pid_max 
  • Or, to persist across reboots, add the following to /etc/sysctl.conf:
    kernel.pid_max = 65536

Sunday, May 22, 2011

Configuring HugePages with Oracle JRockit JVM

Making JRockit JVM use Linux hugepages requires the following 2 configurations:

[1] Mount hugetlbfs
mount -t hugetlbfs nodev /mnt/hugepages
chmod 777 /mnt/hugepages

[2] Use JVM options
-XXaggressive: usually auto enables hugepages, and will use hugepages, if enough available
-Xlargepages: explicitely enables hugepages, and will use if enough hugepages are configured on the system
-Xlargepages:exitOnFailure=true: Will exit if could not use hugepages for any reason