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

时间:2013-06-20 09:28:48

标签: java playframework out-of-memory

在我的应用程序中运行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)

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

非常感谢。

2 个答案:

答案 0 :(得分:3)

答案 1 :(得分:3)

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

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

用户名soft nproc xx

username hard nproc xx

e.g。将10000个最大进程设置为用户ibai

ibai soft 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