Java Memory error: unable to create new native thread Java Memory error: unable to create new native thread multithreading multithreading

Java Memory error: unable to create new native thread


Just got the following information: This is a limitation imposed by my host provider. This has nothing to do with programming, or linux.


The underlying operating system (Debian Linux in this case) does not allow the process to create any more threads. See here how to raise the maximum amount: Maximum number of threads per process in Linux?

I have read on Internet that my program should handle something like 5000 threads or so.

This depends on the limits set to the OS, amount of running processes etc. With correct settings you can easily reach that many threads. I'm running Ubuntu on my own computer, and I can create around 32000 threads before hitting the limit on a single Java program with all my "normal stuff" running on the background (this was done with a test program that just created threads that went to sleep immediately in an infinite loop). Naturally, that high amount of threads actually doing something would probably screech consumer hardware to a halt pretty fast.


Can you try the same command with a smaller stack size "-Xss64k" and pass on the results ?