java ActiveMQ OutOfMemory 无法创建更多线程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1808782/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 18:04:48  来源:igfitidea点击:

ActiveMQ OutOfMemory Can't create more threads

javaactivemq

提问by Marcos Roriz Junior

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.

我在这个页面http://activemq.apache.org/javalangoutofmemory.html 中读到,我可以增加内存大小。但是我该怎么做呢?我需要修改哪个文件,?我试图通过 bin/activemq 脚本传递参数,但没有运气。

回答by habe

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

您的情况对应于大量线程。有3种方法可以解决:

  • reduce number of threads (i.e., -Dorg.apache.activemq.UseDedicatedTaskRunner=falsein the document)
  • reduce per-thread stack size by -Xssoption (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 -Xmxoption to make a room for per-thread stacks (512 MiB by default in ActiveMQ script)
  • 减少线程数(即文档中的-Dorg.apache.activemq.UseDedicatedTaskRunner=false
  • 通过-Xss选项减少每个线程的堆栈大小(默认值:Win/Linux 上的 32 位 Java 为 320 KiB,Win/Linux 上的 64 位 Java 为 1024 KiB,请参阅文档
  • 减少(不扩展)堆大小-Xmx选项为每线程堆栈腾出空间(ActiveMQ 脚本中默认为 512 MiB)

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

注意:如果堆栈或堆太小,则必须导致另一个OutOfMemoryError

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

您可以使用ACTIVEMQ_OPTSshell 变量(在 UNIX 中)指定它们。例如,运行 ActiveMQ 作为

ACTIVEMQ_OPTS=-Xss160k bin/activemq

回答by Gordon

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

您可以使用-Xmx命令参数为 Java 虚拟机分配更多内存。
例如。java -Xmx512M MyClass

回答by Bozho

Check here

在这里查看

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

-Xmx例如,为运行 ActiveMQ 的 VM指定参数 - Tomcat。

回答by Avery Davis

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.confactually controls the number of threads a user can spawn.

我们在 Linux (RedHat Enterprise 5) 系统上遇到了这个问题,并发现在这个构建中,nprocs ulimit/etc/security/limits.conf实际上控制了用户可以产生的线程数。

You can view this limit using the ulimit -acommand.

您可以使用ulimit -a命令查看此限制。

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.

开箱即用,这被设置为 100 的软限制和 150 的硬限制,这与运行现代 App Server 所需的线程数严重不足。
我们完全取消了这个限制,它为我们解决了这个问题。

回答by FelixM

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 decreasingthe 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.

这看起来不像是堆空间用完了,所以不要增加它(-Xmx 选项)。相反,您的应用程序正在耗尽进程内存,减少堆空间将释放进程内存供本机使用。问题是,为什么要使用这么多进程内存?如果您不使用 JNI,您可能创建了太多线程,habe 的帖子解释了如何解决这个问题。