如果你的linux用户跑了很多程序,java进程等等,就有可能出现如下问题:
There is insufficient memory for the Java Runtime Environment to continue.
Cannot create GC thread. Out of system resources.
或者
java.io.IOException: Too many open files
出现这个原因,有可能是系统限制了用户的资源使用,所以需要使用ulimit来设置用户能获得的资源,使用命令:ulimit -a,查看资源配置情况,一般我们需要修改的是open files和max user processes,open files对应的配置是nofile,用户打开文件最大的数量,max user processes对应的配置是nproc,用户启动最大的线程数。
修改/etc/security/limits.conf文件,将noproc和nofile修改成如下值:
* soft noproc 143622
* hard noproc 143622
* soft nofile 196605
* hard nofile 196605
nproc在/etc/security/limit.conf中修改有可能不生效,在/etc/security/limits.d/90-nproc.conf中修改才生效,修改/etc/security/limits.d/90-nproc.conf文件,将nproc修改成如下值:
* soft nproc 143622
* hard nproc 143622
修改后重启或重新ssh连接服务器,使用命令ulimit -a即可看到效果。
参考:
ulimit -a详解
Linux下修改ulimit设置的最大进程