0

my problem is, I have an executable jar file on a ubuntu linux server which starts 41 threads. Now I want to start a second jar file which creates a simular amount of threads and it doesnt work. I get the error:

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

Even when I try t enter java -version I get this error. I lookt at my memory limit and It only uses 10% of the cores and 2 of 8GB ram.

When I enter ulimit -a I got 62987 proccesses per user

And when I look in /proc/sys/kernel/pid_max I got 32768.

I dont know what I should do can someone help me?

Waaal
  • 57
  • 6

1 Answers1

0

There is not enough detail in your question to give a definite answer or solution.


The problem is almost certainly not an OS imposed limit on the number of threads. It is most likely memory related.

You say that 2GB out of 8GB of RAM is in use, but you don't say how you are getting that figure. There are many different ways of measuring memory usage and they mean different things.

When a JVM starts a new thread, it goes to the operating system and asks for a block of memory to hold the thread stack. The default thread stack size is platform specific, but it is typically 1GB. This can be modified by a JVM command line option, or by the application using a Thread constructor that has a stack size parameter. Note that the stack segment is NOT allocated in the Java heap.


So here are some of the possible explanations.

One possibility is that you are running a 32 bit JVM. On a Linux platform, that will limit you to a 4GB address space, and architectural issues will limit the JVM to less than that of actual usable space. If you hit this limit, the OS will refuse a JVM's request for a stack segment. (Check that you have a 64 bit Jave installation and that you haven't given the -d32 command line option.)

A second possibility is that you don't have enough swap space. The OS will only allocate a memory segment if it has enough physical RAM and swap space (page file space) to accommodate the segment. If it figures out that there isn't enough space to hold all of the pages for all of the applications currently running, it will refuse a JVM's request for a stack segment.

A third possibility is that you have configured your JVM with a really large heap, and that is reserving all of the available virtual memory at the system level.

A fourth possibility is that you have accidentally configured a non-default stack size using an -Xss.

A final possibility is that you are actually running more than the 41 threads that you think.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216