你的位置:首页 > 软件开发 > Java > 记一次内存溢出java.lang.OutOfMemoryError: unable to create new native thread

记一次内存溢出java.lang.OutOfMemoryError: unable to create new native thread

发布时间:2016-02-02 12:00:07
一、问题:  春节将至,系统访问量进入高峰期。随之系统出现了异常:java.lang.OutOfMemoryError: unable to create new native thread。在解决这个问题中,尝试了各种方法,最后竟然是因为它......二、解决办法:1、 关于这 ...

一、问题:

  春节将至,系统访问量进入高峰期。随之系统出现了异常:java.lang.OutOfMemoryError: unable to create new native thread。在解决这个问题中,尝试了各种方法,最后竟然是因为它......

二、解决办法:

1、 关于这个问题,一开始猜想是因消息队列(activemq)引起的,因为处理数据较多,开启的线程数较多导致,因此对MQ搭建了集群。

  MQ集群搭建方法:http://blog.csdn.net/jiangxuchen/article/details/8004561

  但是搭建集群后发现,并没有什么卵用,问题依旧。

  继续......

2、 接下来怀疑是系统里开的线程数太多,在优化后,问题仍然存在。

      继续......

3、 内存调优,减小xss值、JVM内存,仍然解决不了。

      继续......

4、 几番周测,在整理思路后,决定首要任务就是如何重现该问题,于是编写测试程序,测试出操作系统最大能够创建的线程数:

    

 1   import java.util.concurrent.CountDownLatch;  2     3   public class TestNativeOutOfMemoryError {  4     5     public static void main(String[] args) {  6     7       for (int i = 0;; i++) {  8         System.out.println("i = " + i);  9         new Thread(new HoldThread()).start(); 10       } 11     } 12    13   } 14    15   class HoldThread extends Thread { 16     CountDownLatch cdl = new CountDownLatch(1); 17    18     public HoldThread() { 19       this.setDaemon(true); 20     } 21    22     public void run() { 23       try { 24         cdl.await(); 25       } catch (InterruptedException e) { 26       } 27     } 28   } 

原标题:记一次内存溢出java.lang.OutOfMemoryError: unable to create new native thread

关键词:JAVA

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。