我正在使用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.
無代碼我們能做什麼? – Divers
DntFrgt2PostDCode – CupawnTae
哈哈,我的壞!更新了代碼 – DntFrgtDSemiCln