Linux下修改ulimit设置的最大进程数(java.lang.OutOfMemoryError: unable to create new native thread)
来源:互联网 发布:csharp和java 编辑:程序博客网 时间:2024/05/02 13:49
最近在Linux服务器上发布应用时碰到一个如下的异常:
Caused by: java.lang.OutOfMemoryError: unable to create new native threadat java.lang.Thread.start0(Native Method)at java.lang.Thread.start(Thread.java:640)
初看可能会认为是系统的内存不足,如果这样想的话就被这段提示带到沟里面去了。
上面这段错误提示的本质是Linux操作系统无法创建更多进程,导致出错。因此要解决这个问题需要修改Linux允许创建更多的进程。
**当然,也要注意你的内存设置大小,如果你分析已足够大,则继续往下看:
修改Linux最大进程数
我们可以通过ulimit -a来查看当前Linux系统的一些系统参数。
$ ulimit -acore file size (blocks, -c) unlimiteddata seg size (kbytes, -d) unlimitedscheduling priority (-e) 0file size (blocks, -f) unlimitedpending signals (-i) 126931max locked memory (kbytes, -l) 64max memory size (kbytes, -m) unlimitedopen files (-n) 1000000pipe size (512 bytes, -p) 8POSIX message queues (bytes, -q) 819200real-time priority (-r) 0stack size (kbytes, -s) 10240cpu time (seconds, -t) unlimitedmax user processes (-u) 1024virtual memory (kbytes, -v) unlimitedfile locks (-x) unlimited
在上面这些参数中,通常我们关注得比较多的是一个进程可打开的最大文件数,即open files。系统允许创建的最大进程数量即是max user processes 这个参数。 我们可以使用 ulimit -u 4096 修改max user processes的值,但是只能在当前终端的这个session里面生效,重新登录后仍然是使用系统默认值。
正确的修改方式是修改/etc/security/limits.d/90-nproc.conf文件中的值。先看一下这个文件包含什么:
$ 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 unlimited
这样系统会根据内存配置情况,自动计算支持进程数
针对线上业务,必须重启才有效。但从
从 OS kernel 2.6.32 开始 :
动态修改mysql进程的limits参数,可以使用如下方式:
echo -n ‘Max processes=SOFT_LIMITS:HARD_LIMITS’ > /proc/进程ID/limits
SOFT_LIMITS:HARD_LIMITS为下表中的项名称,直接替换成你想设置的值即可
通过如上命令就可以动态调整已经存在的mysqld(进程)的processes限制了。
例如,在此实验环境中,操作系统信息如下:
1、ps aux|grep java获得进程ID,如:mx 1787 14.7 28.2 11223628 4593220 即17872、查看进程信息:cat /proc/1787/limits
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 10485760 unlimited bytes
Max core file size unlimited unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 1024 126931 processes
Max open files 1000000 1000000 files
Max locked memory 65536 65536 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 126931 126931 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
3、echo -n "Max processes=40960:126931" > /proc/1787/limits
4、cat /proc/1787/limits
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 10485760 unlimited bytes
Max core file size unlimited unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 40960 126931 processes
Max open files 1000000 1000000 files
Max locked memory 65536 65536 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 126931 126931 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
- Linux下修改ulimit设置的最大进程数(java.lang.OutOfMemoryError: unable to create new native thread)
- linux java.lang.OutOfMemoryError: unable to create new native thread
- java.lang.OutOfMemoryError: unable to create new native thread
- java.lang.OutOfMemoryError: unable to create new native thread
- java.lang.OutOfMemoryError: unable to create new native thread
- 解决 - java.lang.OutOfMemoryError: unable to create new native thread
- 解决 - java.lang.OutOfMemoryError: unable to create new native thread
- 解决 - java.lang.OutOfMemoryError: unable to create new native thread
- 解决 - java.lang.OutOfMemoryError: unable to create new native thread
- 解决 - java.lang.OutOfMemoryError: unable to create new native thread
- java.lang.OutOfMemoryError: unable to create new native thread
- 解决 - java.lang.OutOfMemoryError: unable to create new native thread
- 解决 - java.lang.OutOfMemoryError: unable to create new native thread
- 解决 - java.lang.OutOfMemoryError: unable to create new native thread
- 解决 - java.lang.OutOfMemoryError: unable to create new native thread
- 解决 - java.lang.OutOfMemoryError: unable to create new native thread
- java.lang.OutOfMemoryError: unable to create new native thread
- 解决 - java.lang.OutOfMemoryError: unable to create new native thread
- Combination Sum题解
- ln 命令
- 使用nohup让程序在远程主机后台运行
- 关于QT、QT creator和编译器,新手入门必知的一些知识
- Light OJ 1025 The Specials Menu (区间DP)
- Linux下修改ulimit设置的最大进程数(java.lang.OutOfMemoryError: unable to create new native thread)
- 【blog】博客介绍0v0
- Win7下安装Python图像处理库PIL
- 全面解析均衡效果器之一:EQ原理
- Git学习序列4---分支管理
- Codeforces 24A
- HDU 1506 单调栈
- what is hadoop?
- JavaScript第五课——数据类型(String类型、Object类型)