Sunday, January 4, 2015

Deal With "java.lang.OutOfMemoryError: unable to create new native thread" Error in Java

Upon upgrading CentOS from release 5.3 to 6.4, "java.lang.OutOfMemoryError: unable to create new native thread" is thrown after starting NodeManager in Hadoop for a while. This is because in CentOS 6.x, there is limit to the number of created threads / processes, whose default setting is 1024. In CentOS 5.x, it can be more than 40000 or no limit.
//---- CentOS 5.3 ----
$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 530432
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) unlimited
open files                      (-n) 100000
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) 530432        //Comparison 1
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

//---- CentOS 6.4 ----
$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 514891
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 100000
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          //Comparison 2
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

Thus, we have to enlarge the maximum number of user processes by increasing the number of the following parameter in "/etc/security/limits.d/90-nproc.conf":
*          soft    nproc     1024

Eventually, start a new session for the change to take effect.




No comments:

Post a Comment