我的 Java版本为8 。
我正在测试一个简单的 ThreadPoolExecutor 用例: -
Jconsole显示'Tenured Gen memory'一直在增加,看起来Garbase收集器没有清理内存。
为什么Grabage收集器没有实现Tenured Gen内存?
这是内存泄漏,那么我做错了什么?
Jconsole Tenured Gen截图
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..");
}
}