Outofmemoryerror unable to create new native thread

Java Errors

 

If you are seeing errors like below then please go through below details to resolve the issue

<Jan 1, 2012 4:21:43 PM EDT> <Error> <######> <BEA-382515> <Callout to java method "public static java.lang.String com.EUS.authentication.EUSAuthService.simpleAuthentication(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String)" resulted in exception: null
java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor402.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at stages.transform.runtime.JavaCalloutRuntimeStep$1.run(JavaCalloutRuntimeStep.java:173)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
Truncated. see log file for complete stacktrace
Caused By: 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 org.apache.log4j.PropertyConfigurator.configureAndWatch(PropertyConfigurator.java:375)
at com.***.authentication.AuthServiceHandler.<init>(EUSAuthServiceHandler.java:35)
at com.***.authentication.AuthService.simpleAuthentication(EUSAuthService.java:79)
Truncated. see log file for complete stacktrace

Root Cause Of unable to create new native thread

32 bit architectures limit the amount of memory any single process can allocate to 4 GB (theoretical address space is 2^32 bytes) or even 2 GB, depending on the Operating System.

The total process size in 32 bit mode is limited to 4gb maximum.Java heap and C heap combined, along with other spaces, e.g. for libraries, threads etc. cannot exceed this 4gb limit.

So if you increase the Java heap, e.g. by increasing -Xmx/-Xms from 1.5gb to 2.5gb this will have a significant side effect on the C-heap. Before the increase, the C-heap could easily grow as big as 2gb.

Since there were 4gb -1.5gb = 2.5gb left. AFTER the increase of the Java heap from 1.5gb to 2.5gb we have only 4gb – 2.5gb = 1.5gb left for all the other spaces. Including the C-heap.

While the size of the Java heap can be configured explicitly, this cannot be done for the C-heap. C-heap simply expands until the process size reaches the 4gb limit.

So care must be taken if you configure the Java heap too big.

This can and will result in allocation failures of the C-heap.

E.g. messages such as this one typically mean, that the C-heap was exhausted:

java.lang.OutOfMemoryError: requested 67108872 bytes for Chunk::new. Out of swap space?

The C++ syntax usually seen in logs:

# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (malloc) failed to allocate 65544 bytes

When C-heap was too small. A solution would have been to decrease the Java heap.

but still we can face the classic Java.lang.OutOfMemoryErrors due to insufficient Java heap capacity.

A Java process space consists of the Java heap, the Java permanent generation, the native heap, the threads, mapped files, loaded shared libraries and so on. In other words, the more memory is committed for the Java heap, the perm gen, mapped files, etc, the less memory is available in the native heap and the less Java threads you can create.

If you start an app on Solaris with the following options:

-Xmx2048m -XX:MaxPermSize=1024m -Xss200k

We have reserved 2 GB for the Java heap and 1 GB for the permanent generation. The remaining 1 GB of process space can be used for native heap, thread stacks, shared libraries etc. The more threads an application will start, the smaller the space available for native heap, shared libs, etc. will become.

E.g. the option -Xss200k gives 256k for each Java thread .Actual tests show that we can create up to 3026 threads (approx. 900 MB) with a small test program using the config above with Java SE 6 Update 20 on Solaris. If you try to create more threads, you will get the error message above.

Usually if there were a lot of threads in pooled/waiting state for the log4j code we get above errors.

Probable Solution

Check whether you really need to create so many threads. Also determine the actual requirement of the app and reconfigure the JVM if necessary. You can also use a 64 bit JVM to bypass the 32 bit process size limit.

 

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.