![](/img/trans.png)
[英]PlayFramework custom executors when using CompletableFutures and java
[英]Out of Memory Error when using Executors in java
我正在使用Executors框架(具有无限制阻塞队列的固定线程池)来同时执行任务。
但是,当我运行带有创建的约10000个任务的负载测试时,堆内存(2.1 GB)会大量增加,其中包含约350万个可执行对象。
我不确定是否无限制的队列导致了这种累积。
内存分析器报告:
由“”加载的“ java.util.concurrent.ThreadPoolExecutor”的一个实例占用2,299,506,584(94.97%)个字节。 实例由com.test.ScheduleBean @ 0x743592b28引用,并由“ org.jboss.modules.ModuleClassLoader @ 0x741b4cc40”加载。
任何指针表示赞赏!
//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.
在MemoryAnalyzerTool中编写OQL
从java.util.concurrent.ThreadPoolExecutor中选择*
并执行查询。 它将在单独的窗口中列出对象。 然后右键单击生成的实例,然后
GC根目录的路径->排除软/弱/幻像引用
它将帮助您了解谁对可疑对象拥有强大的参考力。
感谢您的所有回复。
真正的问题是从数据库中提取任务的方式。 重复的任务被添加到任务队列中,因此队列得以建立。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.