Question

I'm simulating a overload of a server and I'm getting this error:

java.lang.OutOfMemoryError: unable to create new native thread

I've read in this page http://activemq.apache.org/javalangoutofmemory.html, that I can increase the memory size. But how do I do that? Which file I need to modify,? I tried to pass the arguments by the bin/activemq script but no luck.

Was it helpful?

Solution

Your case corresponds to massive number of threads. There are 3 ways to solve it:

  • reduce number of threads (i.e., -Dorg.apache.activemq.UseDedicatedTaskRunner=false in the document)
  • reduce per-thread stack size by -Xss option (default values: 320 KiB for 32-bit Java on Win/Linux, 1024 KiB for 64-bit Java on Win/Linux, see doc)
  • reduce (not extend) heap size -Xmx option to make a room for per-thread stacks (512 MiB by default in ActiveMQ script)

Note: If stack or heap is too small, it must cause another OutOfMemoryError.

You can specify them using ACTIVEMQ_OPTS shell variable (in UNIX). For example, run ActiveMQ as

ACTIVEMQ_OPTS=-Xss160k bin/activemq

OTHER TIPS

Check here

Specify the -Xmx argument to the VM that is running the ActiveMQ - Tomcat, for example.

You could assign the Java virtual machine more memory using the -Xmx command argument.
Eg. java -Xmx512M MyClass

We were running into this issue on a Linux (RedHat Enterprise 5) system and discovered that on this build the nprocs ulimit in /etc/security/limits.conf actually controls the number of threads a user can spawn.

You can view this limit using the ulimit -a command.

Out of the box this was set to a soft limit of 100 and a hard limit of 150, which is woefully short of the number of threads necessary to run a modern App Server.
We removed this limit altogether and it solved this issue for us.

This doesn't look like you are running out of heap space, so don't increase that (the -Xmx option). Instead, your application is running out of process memory and decreasing the heap space will free up process memory for native use. The question is, why you are using so much process memory? If you don't use JNI, you probably have created too many threads, and habe's post has explained how to do fix that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top