Vous êtes sur la page 1sur 4

1/10/2017 Howtosolvejava.lang.

OutOfMemoryError:unabletocreatenewnativethread

Please note this website requires cookies in order to function correctly, they do not store any information about you
personally. ACCEPT MORE
INFO

Mastertheboss.com (/)
Home JBoss AS BPM Projects Java EE IDE SOA-Cloud Web Other
(http://www.mastertheboss.com/)

CHEATSHEETS AND MORE DEVELOP APPS JBOSS BOOKS FOLLOW US

Cheatsheet for Admins Start developing Java Learn all about Follow us on Twitter!
EE applications WildFly/JBoss AS ! @mastertheboss

(http://www.mastertheboss.com/jboss- (http://www.mastertheboss.com/java- (http://www.itbuzzpress.com/bookstore.html)


(https://twitter.com/#!/mastertheboss)
server/jboss-script/jboss-wildfly- ee/java-ee-6-tutorials)
cheatsheet-for-linux-
administrators)
JBoss Interview Questions
(http://www.mastertheboss.com/jboss-
server/jboss-configuration/jboss-
wildfly-interview-questions)

MONITORING

How to solve java.lang.OutOfMemoryError: unable to create


new native thread
User Rating: 5 / 5

Please Rate Vote5 Rate


Details Published: 02 September 2012

In Java you can stumble upon two kind of Out of Memory errors:

The java.lang.OutOfMemoryError Java heap space error : This exception will be triggered when the application
attempts to allocate more data into the heap space area, but there is not enough room for it. Although there might
be plenty of memory available on your machine, you have hit the maximum amount of memory allowed by your
(https://ad.doubleclick.net/ddm/jump/N9515.1870623MASTERTHEBOSS/B9351107.127156712;sz=160x600;ord=1484029158?
\) JVM, which can be set through the -Xmx parameter

The java.lang.OutOfMemoryError: Unable to create new native thread happens whenever the JVM asks for a new
thread from the OS. If the underlying OS cannot allocate a new native thread, this OutOfMemoryError will be
thrown.

1)CheckThreadssystemwidesettings
The /proc/sys/kernel/threads-max file provides a system-wide limit for the number of threads. The root user can change
that value if they wish to:

http://www.mastertheboss.com/jbossserver/jbossmonitoring/howtosolvejavalangoutofmemoryerrorunabletocreatenewnativethread 1/4
1/10/2017 Howtosolvejava.lang.OutOfMemoryError:unabletocreatenewnativethread
1 $echo100000>/proc/sys/kernel/threadsmax

You can check the current number of running threads through the /proc/loadavg filesystem:

1 $cat/proc/loadavg
2 0.410.450.573/74928174

Watch the fourth field! This field consists of two numbers separated by a slash (/). The first of these is the number
of currently executing kernel scheduling entities (processes, threads); this will be less than or equal to the number
of CPUs. The value after the slash is the number of kernel scheduling entities that currently exist on the system. In
this case you are running 749 threads

2)Checknumberofprocessesperuser
On a Linux box, threads are essentially just processes with a shared address space. Therefore, you have to check if your
OS allows you enough processes for user. This can be checked through:

ulimita
corefilesize(blocks,c)0
datasegsize(kbytes,d)unlimited
schedulingpriority(e)0
filesize(blocks,f)unlimited
pendingsignals(i)515005
maxlockedmemory(kbytes,l)64
maxmemorysize(kbytes,m)unlimited
openfiles(n)4096
pipesize(512bytes,p)8
POSIXmessagequeues(bytes,q)819200
realtimepriority(r)0
stacksize(kbytes,s)10240
(https://ad.doubleclick.net/ddm/jump/N9518.1870623MASTERTHEBOSS/B7977601.143993227;sz=160x600;ord=1484029158?
\) cputime(seconds,t)unlimited
maxuserprocesses(u)1024
virtualmemory(kbytes,v)unlimited
filelocks(x)unlimited

The default number of process per users is 1024 by default. At this point we will count the number of processes running.
The number of processes running can be counted with a ps output:

1 $pself|wcl
2 220

This number however does not consider the threads which can be spawned by a process. If you try to run ps with a -T
you will see all of the threads as well:

1 $pselfT|wcl
2 385

As you can see the process count increased significantly due to threads. Normally this is never any type of problem,
However in Java based applications this can cause your system to run into system limits! Let's continue our investigation.
Let's see how many Threads are spawned by your JBoss Process. You can do it in at least two ways:

1 $pspJBOSSPIDlfT|wcl

The above shell will return the number of Lightweight Processes created for a Process indicated by the PID. This should
match with the Thread Dump count generated by jstack:

1 $jstacklJBOSSPID|greptid|wcl

Now you should have evidence or not that you need to increase the number of processes for the user. This can be done
with the following command:

1 $ulimitu4096

3)CheckyourthreadsPIDlimit
(https://ad.doubleclick.net/ddm/jump/N9518.1870623MASTERTHEBOSS/B7977601.143993227;sz=160x600;ord=1484029158?
Once that you have counted the number of threads, then you should verify that you are not hitting system limits,
\)
specified by the kernel.pid_max limit parameter. You can check this value by executing:

1 $sysctla|grepkernel.pid_max
2
3 kernel.pid_max=32768
http://www.mastertheboss.com/jbossserver/jbossmonitoring/howtosolvejavalangoutofmemoryerrorunabletocreatenewnativethread 2/4
1/10/2017 Howtosolvejava.lang.OutOfMemoryError:unabletocreatenewnativethread

WILDFLY 10 BOOK 4)ReducetheThreadStacksize


Another option which you can use, if you are not able to modify the OS settings is reducing the stack size. The JVM has
an interesting implementation, by which the more memory is allocated for the heap (not necessarily used by the heap),
the less memory available in the stack, and since threads are made from the stack, in practice this means more
memory in the heap sense (which is usually what people talk about) results in less threads being able to run
concurrently.

First of all check the default Thread Stack size which is dependent on your Operating System:

1 $javaXX:+PrintFlagsFinalversion|grepThreadStackSize
2 intxThreadStackSize=1024{pdproduct}

(http://www.itbuzzpress.com/bookstore.html)
As you can see, the default Thread Stack Size is 1024 kb in our machine. In order to reduce the stack size, add -Xss
option to the JVM options. In JBoss EAP 6 / WildFly the minimum Thread stack size is 228kb. You can change it in
Standalone mode by varying the JAVA_OPTS as in the following example:

1 JAVA_OPTS="Xms128mXmx1303mXss256k"

In Domain Mode, you can configure the jvm element at various level (Host, Server Group, Server). There you can set the
requested Stack Size as in the following section:

1 <jvmname="default">
2 <heapsize="64m"maxsize="256m"/>
3 <jvmoptions>
4 <optionvalue="server"/>
5 <optionvalue="Xss256k"/>
6 </jvmoptions>
7 </jvm>

(https://ad.doubleclick.net/jump/N9515.1870623MASTERTHEBOSS/B8442184.114272586;sz=300x250;ord=1484029158?
\)

Relatedarticlesavailableonmastertheboss.com

HOWTOMONITORJBOSSCPUUSAGE?

JBoss AS 7 users and WildFly can use JConsole in order to moni

(/jboss-server/jboss-monitoring/how-to-monitor-jboss-cpu-usage) (/jboss-server/jboss-monitoring/how-to-

HOWTOMONITORJBOSSGRAPHICALLY?

Youve been using the JMX Console to access yourMBeans. In thi

monitor-jboss-graphically) (/jboss-server/jboss-monitoring/how-to-monitor-jboss-with-snapshots) (/jboss-

HOWTOMONITORJBOSSWITHSNAPSHOTS?

http://www.mastertheboss.com/jbossserver/jbossmonitoring/howtosolvejavalangoutofmemoryerrorunabletocreatenewnativethread 3/4
1/10/2017 Howtosolvejava.lang.OutOfMemoryError:unabletocreatenewnativethread
JBoss gives you the ability to capture data not only in real t

JBOSSALARMCONFIGURATION

An Alarm indicates that an event (generally an error) has happene

server/jboss-monitoring/jboss-alarm-configuration) (/jboss-server/jboss-monitoring/monitoring-jboss-ejb-container)

MONITORINGJBOSSEJBCONTAINER

In this article we will show how easily you can write an Intercep

MONITORJBOSSASWITHJOLOKIA

Jolokia is a cool monitoring solution for accessing JMX MBeans re

(/jboss-server/jboss-monitoring/monitor-jboss-as-with-jolokia) (/jboss-server/jboss-monitoring/monitor-your-jboss-
resources-using-the-dmr-api) (/jboss-server/jboss-monitoring/using-jconsole-to-monitor-a-remote-wildfly-server)
(/jboss-server/jboss-monitoring/getting-started-with-appdynamics-and-jboss-wildfly) (/jboss-server/jboss-
monitoring/monitor-wildfly-with-your-bash-skills) (/jboss-server/jboss-monitoring/hawtio-quickstart-tutorial)
(/jboss-server/jboss-monitoring/hawkular-tutorial) (/jboss-server/jboss-monitoring/monitoring-wildfly-mbeans-
from-the-shell)

Load More...

JBOSS TRAINING FOLLOW US ON TWITTER

Widest choice of JBoss/WildFly Training! Follow us on Twitter! @mastertheboss


(http://www.mastertheboss.com/jboss- (https://twitter.com/#!/mastertheboss)
courses/jbossas7training/jboss-as-7-training)

TOP

http://www.mastertheboss.com/jbossserver/jbossmonitoring/howtosolvejavalangoutofmemoryerrorunabletocreatenewnativethread 4/4

Vous aimerez peut-être aussi