spring - Poller 任务执行器内存泄漏
问题描述
我正在构建一个企业应用程序,并且我正在使用活动 mq 进行应用程序之间的内部通信。当我将任务执行器与轮询器 AbstractPollingEndpoint 和 ErrorHandlingTaskExecutor 对象实例一起使用时,会导致内存泄漏。即使应用程序处于空闲模式,堆中的对象计数也会增加。当我关闭这部分代码
.taskExecutor(outTaskExecutor)
时,问题不再发生。但是我们正在为繁忙的流量做准备,我们不需要提供更多的线程来处理消息。我究竟做错了什么?你能帮忙吗?谢谢
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();
解决方案
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
推荐阅读
- javascript - 使用钩子响应状态更新
- reactjs - 如何抑制有效 useEffect 实例的 linting?
- google-identity - Google 身份平台,无法启用
- python - 将 MM-DD 添加到 Python 年份
- flutter - 如何获取音频文件的长度而不在 Flutter/Dart 中播放
- php - phpseclib 1.0 是否与 PHP 7.3 兼容?
- node.js - Mongoose document.save() 抛出“验证失败”
- r - SMOTE 有超过 2 个班级?
- curly-braces - clang 格式可以在所有控制语句主体上强制支撑吗?
- javascript - 使用 javascript 和 ajax 从 mysql 获取数据时出错