您的位置:首页 > 编程语言 > Java开发

解决java.lang.OutOfMemoryError: unable to create new native thread问题

2016-06-12 14:36 896 查看
问题:

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)  

解决:

1.升级JVM到最新的版本

    最新版本的JVM一般在内存优化方面做的更好,升级JVM到最新的版本可能会缓解测问题

2.从操作系统层面去解决

    使用64位操作系统

    如果使用32位操作系统遇到unable to create new native thread,建议使用64位操作系统

3.增大OS对线程的限制

    如果使用Red Hat Enterprise Linux 6,编辑/etc/security/limits.d/90-nproc.conf,添加如下配置:
# /etc/security/limits.d/90-nproc.conf
*          soft    nproc     1024
root       soft    nproc     unlimited

user       -       nproc     2048
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: