我正在使用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