Max User Processes and Java OutOfMemoryError "unable to create new native thread"

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

Internal

Overview

java.lang.OutOfMemoryError: unable to create new native thread
        at java.lang.Thread.start0(Native Method) [rt.jar:1.8.0_51]
        at java.lang.Thread.start(Thread.java:714) [rt.jar:1.8.0_51]
        ...

java.lang.OutOfMemoryError "unable to create new native thread" is usually the result of the java process attempting to create more threads than the system "max user processes" limit.

To figure out the number of threads, monitor the JVM, or use MCS, or read that number from /proc TODO: how?.

Then, read the number of maximum user processes allowed for the UNIX user that runs that JVM. Look for "max user processes":

[jbossusr@tcffevt1r6ap02 ~]$ ulimit -an

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

or

ulimit -u

Then increase that number in /etc/security/limits.conf.

Also see:

ulimit /etc/security/limits.conf

For more details on how Java threads map onto Linux processes, see

Java Threads and Linux Processes