​http://dubbo.io/User+Guide-zh.htm 用户指南>>线程模型​


类似于数据库的连接池 Linux 用户线程数限制导致的 Java.lang.OutOfMemoryError: unable to create new native thread异常


系统默认最大的线程数为1024个


[root@liuyazhuang131 ~]# cat /etc/security/limits.d/90-nproc.conf 
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.
* soft nproc 1024
root soft nproc unlimited
[root@liuyazhuang131 ~]# vi /etc/security/limits.d/90-nproc.conf

调整时要注意:


1、 尽量不要使用 root 用户来部署应用程序,避免资源耗尽后无法登录操作系统。因为root用户默认没有限制线程数,如果线程过多,会使资源占用很多,导致不能关机,只能硬关机


2、 普通用户的线程数限制值要看可用物理内存容量来配置

[root@liuyazhuang131 ~]# cat /proc/meminfo |grep MemTotal 
MemTotal: 2941144 kB
[root@liuyazhuang131 ~]# echo "2941144/128"|bc
22977
[root@liuyazhuang131 ~]# ulimit -u
1024
[1]+ Stopped vi /etc/security/limits.d/90-nproc.conf
[root@liuyazhuang131 ~]# vi /etc/security/limits.d/90-nproc.conf
[root@liuyazhuang131 ~]# cat /etc/security/limits.d/90-nproc.conf
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.
* soft nproc 12000
root soft nproc unlimited
[root@liuyazhuang131 ~]#
计算方式:
default_nproc = total_memory/128K;
$ cat /proc/meminfo |grep MemTotal
$ echo "2941144/128"|bc
$ ulimit -u
ulimit -a # 显示目前资源限制的设定
ulimit -u # 用户最多可开启的程序数目
重启,使之生效:# reboot