OutOfMemoryError: unable to create new native thread
Asked by Werner Baderschneider:

I'm trying to install Confluence on an Ubuntu 18.04 System with Postgres DB but it fails with the above mentioned Error.

What I did so far:

- increase Java Heap in setenv.sh to 2048M

- insert the following lines into /etc/security/limits.conf:

confluence soft nofile 4096  
confluence hard nofile 8192  
confluence soft nproc 4096  
confluence hard nproc 8192

The System is a freshly installed VM at a Provider, so no other thread consuming processes should run besides postgres and confluence.

Any hints?


Answers:
author: Werner Baderschneider
body: I love self healing systems... :-(

I don't know, which change was the one that helped, but additionally to the above mentioned ones I did the following changes:

/etc/systemd/system.conf  
DefaultTasksMax=12288

/etc/systemd/logind.conf  
UserTasksMax=51200

Then I did a

/etc/init.d/procps restart

, left for the weekend and when I came back today, it worked.

No idea, why.

comments: author: Sascha
body: Thanks for posting how you resolved the situation! I had the exact same issue (with the only difference using JIRA instead of Confluence) with the JVM not being able to spawn new processes, even if the configured limits were not reached yet and more than enough RAM still available.

I am not sure yet why your proposed config changes resolved the situation, because those limits were already properly set and applied to the process that JIRA is running in. Therefore, those Ubuntu-wide settings should not have mattered... But apparently, adjusting those settings did resolve the issue, so thank you!


author: Stephen Sifers
body: Hello Werner and welcome to the Community!

It looks like you've configured your memory settings as per the recommendations when this error is present. For others, the referenced recommendations are at [Confluence crashes and throws 'OutOfMemory: unable to create new native thread' error](https://confluence.atlassian.com/confkb/confluence-crashes-and-throws-outofmemory-unable-to-create-new-native-thread-error-423628320.html). Since you're still getting this error with the memory adjusted and on a new install it leads us to believe these are a possible memory issue on the host or a java issues. Could you please let us know the following?

* How much memory is allocated to this VM (total RAM)?
* What version and bitness for Java (32 or 64bit with version)?

We look forward to hearing back to ensure your Confluence instance is up and running.

Regards,  
Stephen Sifers

comments: author: Werner Baderschneider
body: The VM has 12 GB of RAM:

```
top - 16:13:29 up 9 days, 18:53, 1 user, load average: 0,23, 1,49, 1,52
Tasks: 101 gesamt, 1 laufend, 100 schlafend, 0 gestoppt, 0 Zombie
%CPU(s): 0,2 be, 0,1 sy, 0,0 ni, 99,7 un, 0,0 wa, 0,0 hi, 0,0 si, 0,0 st
KiB Spch : 12582912 gesamt, 6836456 frei, 4692440 belegt, 1054016 Puff/Cache
KiB Swap: 0 gesamt, 0 frei, 0 belegt. 7828320 verf? Sp
```

I tried it with OpenJDK-8 64bit as well as with Orcale-JDK-8 64bit:

```
confluence@xxxxx:/app/confluence-6.15.4/bin$ java -version
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b03-0ubuntu1.18.04.1-b03)
OpenJDK 64-Bit Server VM (build 25.212-b03, mixed mode)
[...]
confluence@xxxxx:/app/confluence-6.15.4/bin$ java -version
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
```

Here you can see the properties of the tomcat process:

```
confluence@xxxxx:/app/confluence-6.15.4/bin$ ps aux |grep java
conflue+ 27620 155 13.7 8107968 1736368 pts/0 Sl 16:07 0:23 /usr/bin/java -Djava.util.logging.config.file=/app/confluence-6.15.4/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -XX:ReservedCodeCacheSize=256m -XX:+UseCodeCacheFlushing -Dconfluence.context.path= -Datlassian.plugins.startup.options= -Dorg.apache.tomcat.websocket.DEFAULT_BUFFER_SIZE=32768 -Dsynchrony.enable.xhr.fallback=true -Xms4096m -Xmx4096m -XX:+UseG1GC -Datlassian.plugins.enable.wait=300 -Djava.awt.headless=true -XX:G1ReservePercent=20 -Xloggc:/app/confluence-6.15.4/logs/gc-2019-06-02_16-07-40.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M -XX:-PrintGCDetails -XX:+PrintGCDateStamps -XX:-PrintTenuringDistribution -Dignore.endorsed.dirs= -classpath /app/confluence-6.15.4/bin/bootstrap.jar:/app/confluence-6.15.4/bin/tomcat-juli.jar -Dcatalina.base=/app/confluence-6.15.4 -Dcatalina.home=/app/confluence-6.15.4 -Djava.io.tmpdir=/app/confluence-6.15.4/temp org.apache.catalina.startup.Bootstrap start
```


Tags: confluence-server

server