java.lang.OutOfMemoryError: 无法在 Java (Play Framework) 中创建新的本机线程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17210095/
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-11-01 01:19:27  来源:igfitidea点击:

java.lang.OutOfMemoryError: unable to create new native thread in Java (Play Framework)

javaplayframeworkout-of-memory

提问by MadTech

In my application runs in amazon aws instance. In these i am getting the java.lang.OutofMemory error. My instance is running in ubuntu machine. Following is error I am getting. I have google about this but I am not find any solution about this error.

在我的应用程序中运行在 amazon aws 实例中。在这些中,我收到了 java.lang.OutofMemory 错误。我的实例在 ubuntu 机器上运行。以下是我得到的错误。我有关于这个的谷歌,但我没有找到关于这个错误的任何解决方案。

    java.lang.OutOfMemoryError: unable to create new native thread
        at java.lang.Thread.start0(Native Method)
        at java.lang.Thread.start(Thread.java:640)
        at java.util.concurrent.ThreadPoolExecutor.addIfUnderMaximumPoolSize(ThreadPoolExecutor.java:727)
        at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:657)
        at org.apache.tomcat.util.threads.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:176)
        at org.apache.tomcat.util.threads.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:156)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:325)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)

I want to know when these error is arise and how we will prevent this.

我想知道这些错误何时出现以及我们将如何防止这种情况发生。

Thanks inadvance.

提前致谢。

回答by ibai

I had the same issue when running a lot of concurrent processes testing my application with JMeter. I am using Fedora and by default the process amount available is 1024.

在使用 JMeter 运行大量并发进程测试我的应用程序时,我遇到了同样的问题。我正在使用 Fedora,默认情况下可用的进程数量是 1024。

You can check your maximum amount of processes by entering ulimit -uin the command line, and to change the amount of maximum processes permanently, you just have to edit the file under /etc/security/limits.confand add the following lines in the end of the file:

您可以通过在命令行中输入ulimit -u来检查最大进程数,并且要永久更改最大进程数,您只需编辑/etc/security/limits.conf下的文件并添加以下行文件的结尾:

username soft nproc xx

用户名 soft nproc xx

username hard nproc xx

用户名 hard nproc xx

e.g. set 10000 max processes to user ibai

例如为用户 ibai 设置 10000 个最大进程

ibai soft nproc 10000

ibai soft nproc 10000

ibai hard nproc 10000

ibai hard nproc 10000

https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Tuning_and_Optimizing_Red_Hat_Enterprise_Linux_for_Oracle_9i_and_10g_Databases/sect-Oracle_9i_and_10g_Tuning_Guide-Setting_Shell_Limits_for_the_Oracle_User-Limiting_Maximum_Number_of_Processes_Available_for_the_Oracle_User.html

https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Tuning_and_Optimizing_Red_Hat_Enterprise_Linux_for_Oracle_9i_and_10g_Databases/sect-Oracle_9i_and_10g_Tuning_ProcessLimiting_Databases.Oracle_ProcessLimiting_Oracle_Maximing_ProcessLimiting_Oracle_Maximing_ProcessLimiting_Databases_Oracle_Maximing_ProcessLimiting_Oracle-User_Setting_Oracle