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

tomcat的web项目压力测试时,测试了几秒钟,web服务开始无响应。tomcat的日志中看到如下错误:

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

查了以下该process开启的线程数为3366

$ pstree -p 22750 | wc -l
3366

而此时内存消耗量并不大,然后又用 ulimit -a查看了各个限制,发现 max user processes 才4096。

然后修改 /etc/security/limits.conf ,下方添加以下内容(webadmin是启动tomcat的用户):

root        -       nofile  655360
root        -       nproc   655360
webadmin        -       nofile  409600
webadmin        -       nproc   409600

然后再看ulimit,就没问题了

原文地址:https://www.cnblogs.com/got-my-way/p/8016183.html