首页 > 解决方案 > Poller 任务执行器内存泄漏

问题描述

我正在构建一个企业应用程序,并且我正在使用活动 mq 进行应用程序之间的内部通信。当我将任务执行器与轮询器 AbstractPollingEndpoint 和 ErrorHandlingTaskExecutor 对象实例一起使用时,会导致内存泄漏。即使应用程序处于空闲模式,堆中的对象计数也会增加。当我关闭这部分代码 .taskExecutor(outTaskExecutor) 时,问题不再发生。但是我们正在为繁忙的流量做准备,我们不需要提供更多的线程来处理消息。我究竟做错了什么?你能帮忙吗?谢谢

可视 VM 堆比较

Executor Service outTaskExecutor = Executors.newFixedThreadPool(10);

IntegrationFlow jmsOutbound = IntegrationFlows.from(jmsInChannel)
                .handle(Jms.outboundAdapter(this.jmsTemplate.getConnectionFactory())
                                .destinationExpression("headers['responseQueueName']")
                        , s -> s.poller(p -> p.fixedDelay(pollerDelay).taskExecutor(outTaskExecutor)).get())
                .get();
        this.flowContext.registration(jmsOutbound).id("jmsOutbound").register();

标签: springspring-integrationdslpoller

解决方案


Executor Service outTaskExecutor = Executors.newFixedThreadPool(10);对于每一个动态流来说,它看起来都不合适。为什么不将其作为单例并与所有动态流共享?

还要注意文档中类似问题的描述:https ://docs.spring.io/spring-integration/reference/html/#async-polling

加上这个 SO 问题:Memory leak because of receive timeout and task executor out of tune conf


推荐阅读