0

我正在使用Executors框架(固定线程池和无界阻塞队列)并发执行任务。在java中使用Executors时出现内存不足错误

但是当我运行一个大约10000个任务创建的负载测试时,有大量的堆内存(2.1 GB)和大约350万个可执行对象。

我不确定无界队列是否导致这种构建。

内存分析器报告:

“java.util.concurrent.ThreadPoolExecutor中” 由 加载的

一个实例 “” 占用2299506584(94.97%)字节。 实例由com.test.ScheduleBean @ 0x743592b28引用,由​​“org.jboss.modules.ModuleClassLoader @ 0x741b4cc40”加载 。

任何指针赞赏!在MemoryAnalyzerTool

SELECT *

 //The Executors are loaded in a hashmap 
     HashMap<String,Executor> poolExecutorMap = new HashMap<String,Executor>(); 

     //Executor is a fixed thread pool one 
     Executor poolExecutor = Executors.newFixedThreadPool(threadCount); 

     //then add the executor to the hashmap 
     poolExecutorMap.put("Executor", poolExecutor); 



    //then a list of tasks are pulled from a database and passed as runnable objects to the executors 

     Class<?> monitorClass=null; 

     List<Task> list = getAllTasksToProcess(); 

    for (int i = 0; i < list.size(); i++) { 
     Task task = list.get((int) i); 

    monitorClass = Class.forName(task.getTask_event_name()); 
     Constructor<?> ctor; 
     ctor = monitorClass.getConstructor(Task.class); 
     Object object = ctor.newInstance(task); 
     logger.debug("Adding task number : "+task.getTask_sequence_id()); 
     poolExecutorMap.get("Executor").execute((Runnable) object); 
} 



// the executor classes have an execute method which sends a http notification. 
+0

无代码我们能做什么? – Divers

+2

DntFrgt2PostDCode – CupawnTae

+0

哈哈,我的坏!更新了代码 – DntFrgtDSemiCln

回答

0

感谢您的回复。

真正的问题是从数据库中提取任务的方式。 重复的任务正在被添加到任务队列中,因此队列会建立起来。

2

写OQL从java.util.concurrent.ThreadPoolExecutor中

并执行查询。它将在单独的窗口中列出对象。 然后右键点击生成然后

路径GC根所实例 - >排除软/弱/虚引用

它将帮助您了解是谁在持有怀疑的对象的强引用。

相关问题