Unhandled exception 'java.lang.OutOfMemoryError: unable to create native thread: possibly out of memory or process/resource limits reached

916 views Asked by At

We have recently migrated a springboot application to 2.7.11 version, and while performing a load test, a nasty error raised :

"Unhandled exception 'java.lang.OutOfMemoryError: unable to create native thread: possibly out of memory or process/resource limits reached

we noticed that the app now consumes a bit more memory than lhe last version, so i tried to collect some profiling infos through visualvm, and i noticed that a forkjoinpool (a custom thread pool with parallelism is set to 5) is creating many thread than expected (300 thread instead of 5): enter image description here

Roughly speaking, the app parse a big json file and cuts it into several pieces, and foreach part we send a task to the forkjoinpool through executor.execute().

Noting that we are serving this application on openshift V4, and we've never got this weird error when using springboot 2.6.6.

2

There are 2 answers

0
OMARoun On

If your tasks take a long time to execute, there's a risk that ForkJoinPool could create additional threads to maintain a degree of parallelism.

0
k314159 On

Just because you have 300 threads in the ThreadGroup named "ForkJoinPool", it doesn't mean all of those threads were created by the ForkJoinPool. If the runnable tasks themselves create separate (sub-) threads, those threads will also be in the same thread group. Given that your ForkJoinPool has a parallelism of only 5, it is the most likely case that your threads are themselves creating other threads. Check the code of the threads created by your ForkJoinPool.