OutOfMemoryerror unable to create new native thread

Copy file to shared folder java

The OutOfMemoryError is due to : unable to create new native thread which indicates there is no issues with Java Heap Size or Memory leak or Java GC unable to reclaim memory. The reason for the exception java.lang.OutOfMemoryError: unable to create new native thread is due to: JVM asking a new thread and the underlying OS cannot allocate a new thread anymore as there is not enough stack memory that can be allocated.

1. Please perform below steps on the OS to fix the native threads issue as well as other OS limits related issues:
a. Increasing the File Descriptor Limit. The file descriptor limit can be increased using the following procedure:
i. Edit /etc/security/limits.conf and add the lines before End of file:

             * soft nofile 65536
             * hard nofile 65536

ii. Edit /etc/pam.d/login, adding the line:

              session required /lib/security/pam_limits.so

iii. The system file descriptor limit is set in /proc/sys/fs/file-max. The following command will increase the limit to 65536:

              echo 65536 > /proc/sys/fs/file-max

iv. Make sure open files (-n) is 65536 by typing the following command:

              ulimit –aH

b. As same user runs the JVM service it is necessary to increase the number of processes and few other parameters for users.
i. Edit /etc/security/limits.conf and add the below lines before End of file:

                *          soft   nproc       2047
                *         hard   nproc       62447

ii. Edit /etc/sysctl.conf and add below line to the file.

                 sys.kernel.threads-max = 999999
                 sys.kernel.pid_max = 999999
                 sys.vm.max_map_count = 1999999
                 echo 1999999 > /proc/sys/vm/max_map_count
                 echo 999999 > /proc/sys/kernel/pid_max
                 echo 999999 > /proc/sys/kernel/threads-max

c. Reboot the Linux VM post completion of above updates.
2. Check the output of below command after reboot for review:

          a.	ulimit -aH
          b.	cat /proc/sys/fs/file-max
          c.	cat /proc/sys/vm/max_map_count
          d.	cat /proc/sys/kernel/pid_max
          e.	cat /proc/sys/kernel/threads-max

References:

http://xmlandmore.blogspot.com/2014/09/jdk-8-thread-stack-size-tuning.html
http://www.java67.com/2016/10/javalangoutofmemoryerror-unable-to-create-new-native-thread-in-java-solution.html
http://www.mastertheboss.com/jboss-server/jboss-monitoring/how-to-solve-javalangoutofmemoryerror-unable-to-create-new-native-thread
https://stackoverflow.com/questions/34452302/how-to-increase-maximum-number-of-jvm-threads-linux-64bit

In case of any ©Copyright or missing credits issue please check CopyRights page for faster resolutions.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.