Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.OutOfMemoryError: unable to create new native thread in Java (Play Framework)

In my application runs in amazon aws instance. In these i am getting the java.lang.OutofMemory error. My instance is running in ubuntu machine. Following is error I am getting. I have google about this but I am not find any solution about this error.

    java.lang.OutOfMemoryError: unable to create new native thread
        at java.lang.Thread.start0(Native Method)
        at java.lang.Thread.start(Thread.java:640)
        at java.util.concurrent.ThreadPoolExecutor.addIfUnderMaximumPoolSize(ThreadPoolExecutor.java:727)
        at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:657)
        at org.apache.tomcat.util.threads.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:176)
        at org.apache.tomcat.util.threads.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:156)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:325)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)

I want to know when these error is arise and how we will prevent this.

Thanks inadvance.

like image 642
MadTech Avatar asked Jun 20 '13 09:06

MadTech


People also ask

What went wrong unable to create new native thread?

OutOfMemoryError: Unable to create new native thread means that the Java application has hit the limit of how many Threads it can launch.

What is native thread in Java?

"Native threads" refers to a in which the Java virtual machine creates and manages Java threads using the operating system threads library - named libthread on UnixWare - and each Java thread is mapped to one threads library thread.

Why out of memory error occurs in Java?

OutOfMemoryError exception. Usually, this error is thrown when there is insufficient space to allocate an object in the Java heap. In this case, The garbage collector cannot make space available to accommodate a new object, and the heap cannot be expanded further.

How many threads the OS will allow your JVM to use?

Each JVM server can have a maximum of 256 threads to run Java applications.


1 Answers

I had the same issue when running a lot of concurrent processes testing my application with JMeter. I am using Fedora and by default the process amount available is 1024.

You can check your maximum amount of processes by entering ulimit -u in the command line, and to change the amount of maximum processes permanently, you just have to edit the file under /etc/security/limits.conf and add the following lines in the end of the file:

username soft nproc xx

username hard nproc xx

e.g. set 10000 max processes to user ibai

ibai soft nproc 10000

ibai hard nproc 10000

https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Tuning_and_Optimizing_Red_Hat_Enterprise_Linux_for_Oracle_9i_and_10g_Databases/sect-Oracle_9i_and_10g_Tuning_Guide-Setting_Shell_Limits_for_the_Oracle_User-Limiting_Maximum_Number_of_Processes_Available_for_the_Oracle_User.html

like image 155
ibai Avatar answered Oct 12 '22 17:10

ibai