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

来源:互联网 发布:淘宝转化率25%算正常吗 编辑:程序博客网 时间:2024/05/22 16:48

问题:

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  


0 0
原创粉丝点击