在Java 8中,Tenured Gen内存总是在增加

时间:2016-11-11 12:43:14

标签: java multithreading executorservice

我的 Java版本为8

我正在测试一个简单的 ThreadPoolExecutor 用例: -

  • 使用ThreadPoolExecutor执行新线程
  • 在新主题中打印已完成的消息

Jconsole显示'Tenured Gen memory'一直在增加,看起来Garbase收集器没有清理内存。

为什么Grabage收集器没有实现Tenured Gen内存?

这是内存泄漏,那么我做错了什么?

Jconsole Tenured Gen截图

**Jconsole Tenured Gen screenshot**

App.java

    public static int n = 0;
    private static int coreThreads = 40;
    private static int maxThreads = 200;
    private static int queueSize = 20;
    public static volatile boolean shuttingDown = false;
    final static BlockingQueue<Runnable> queue = new ArrayBlockingQueue<Runnable>(queueSize);
    final static  ThreadPoolExecutor reqExecutor = new ThreadPoolExecutor(coreThreads, maxThreads, 0L, TimeUnit.MILLISECONDS, queue);    

public static void main( String[] args ) 
            {


                    System.out.println("App started...");
                    while(true){
                        for (int i = 0; i < 100; i++) 
                        {
                            reqExecutor.execute(new MulThread_Test());
                            /*reqExecutor.execute(new Runnable() {

                                public void run() {
                                    // TODO Auto-generated method stub
                                    System.out.println("##############");
                                }
                            });*/
                        }
                        System.out.println("100 reqExecutor done.");
                        Thread.sleep(1000);
                }   
             }

MulThread_Test.java

  public class MulThread implements Runnable
{

    public void run()
    {
        try {
            execute();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println("Finshed..!");
    }



    public void execute() throws InterruptedException
    {
        System.out.println("working..");

    }
}

0 个答案:

没有答案