JVM 系列二:java.lang.OutOfMemoryError: unable to create new native thread
来源:互联网 发布:4399页游刷元宝软件 编辑:程序博客网 时间:2024/05/22 13:40
问题描述
Java程序运行过程中抛出java.lang.OutOfMemoryError: unable to create new native thread,如下所示:
java.lang.OutOfMemoryError: unable to create new native thread at java.lang.Thread.start0(Native Method) at java.lang.Thread.start(Thread.java:691) at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:949) at java.util.concurrent.ThreadPoolExecutor.processWorkerExit(ThreadPoolExecutor.java:1017) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1163) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.OutOfMemoryErrorat java.util.zip.ZipFile.open(Native Method)at java.util.zip.ZipFile.<init>(ZipFile.java:214)at java.util.zip.ZipFile.<init>(ZipFile.java:144)at java.util.jar.JarFile.<init>(JarFile.java:153)at java.util.jar.JarFile.<init>(JarFile.java:117)
从JVM层面去解决
减小thread stack的大小
JVM默认thread stack的大小为1024,这样当线程多时导致Native virtual memory被耗尽,实际上当thread stack的大小为128K 或 256K时是足够的,所以我们如果明确指定thread stack为128K 或 256K即可,具体使用-Xss,例如在JVM启动的JVM_OPT中添加如下配置
-Xss128k
减小heap或permgen初始分配的大小
如果JVM启动的JVM_OPT中有如下配置
-Xms1303m -Xmx1303m -XX:PermSize=256m -XX:MaxPermSize=256m我们可以删除或减小初始化最小值的配置,如下
-Xms256m -Xmx1303m -XX:PermSize=64m -XX:MaxPermSize=256m
-Xmx1303m -XX:MaxPermSize=256m
升级JVM到最新的版本
最新版本的JVM一般在内存优化方面做的更好,升级JVM到最新的版本可能会缓解测问题
从操作系统层面去解决
使用64位操作系统
如果使用32位操作系统遇到unable to create new native thread,建议使用64位操作系统
增大OS对线程的限制
在Linux操作系统设定nofile和nproc,具体编辑/etc/security/limits.conf添加如下:
soft nofile 2048 hard nofile 8192
soft nproc 2048 hard nproc 8192
如果使用Red Hat Enterprise Linux 6,编辑
/etc/security/limits.d/90-nproc.conf,添加如下配置:
# cat /etc/security/limits.d/90-nproc.conf* soft nproc 1024root soft nproc unlimiteduser - nproc 2048
- JVM 系列二:java.lang.OutOfMemoryError: unable to create new native thread
- JVM - 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
- 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
- DM8168/DVRRDK开发中Link模块的创建以及alg自己算法的植入
- 走进“开心农场主”:游戏数据分析的架构及调优
- WINCE TOC解析 文章2
- 符号执行平台S2E的安装
- Canny详解(转载)
- JVM 系列二:java.lang.OutOfMemoryError: unable to create new native thread
- 如何在遍历中使用list的删除函数
- 解剖cloudfoundry(二)--之前准备的工作
- 细说Qt 已注册元对象类型
- Android使用Intent发送短信SMS
- Hibernate 的 session 管理
- nginx+lua实现视频的过期防盗链
- primary key与unique的区别
- 怎样取消linux挂载磁盘不在桌面上显示