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根所實例 - >排除軟/弱/虛引用

它將幫助您瞭解是誰在持有懷疑的對象的強引用。

相關問題