I have a Ubuntu 16.04.5 server which runs multiple Java applications as root. The applications regularly (about every 30min to 1h) crash from a OutOfMemoryError: unable to create new native thread
. Something I noticed is that applications don't crash alone, but instead multiple applications crash at the same time.
I don't know what causes this and I'm having trouble finding out what I need to change to fix the issue.
I followed some articles about the error and went through multiple possible causes, but they don't seem to apply to my situation:
Fix thread creation rate
The applications regularly create threads, but many threads die as well. This means the concurrent thread count never rises above about 10k. I checked whether I have an issue with runaway thread creation by generating thread dumps and counting threads, but the number of threads never exceeds the previously mentioned 10k.
Increase the thread limits of the os
When I run ulimit -u
it returns 1546669
.
This should be enough, right?
Allocate more RAM to the machine
I use about 7GB of an available 16GB RAM. This is my htop view:
Additional info
Java version:
The full error stacktrace of the error:
java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:717)
at de.domisum.lib.auxilium.util.java.ThreadUtil.createAndStartThread(ThreadUtil.java:126)
at de.domisum.lib.auxilium.util.java.ThreadUtil.createAndStartThread(ThreadUtil.java:114)
at de.domisum.lib.auxilium.run.RunNotifyOnTimeout.run(RunNotifyOnTimeout.java:32)
at de.domisum.lib.auxilium.util.ticker.Ticker.tickWithTimeout(Ticker.java:119)
at de.domisum.lib.auxilium.util.ticker.Ticker.run(Ticker.java:108)
at java.lang.Thread.run(Thread.java:748)
A thread dump from an application that suffered from the error: thread dump