我是使用 Apache Camel 的新手,但从我的各种测试中,我意识到使用 JMS 作为队列 channel 会造成内存泄漏,因为每条消息消耗后所使用的内存并没有减少。
一个简单的例子可以更好地描述它:
public static void main(String args[]) throws Exception {
CamelContext context = new DefaultCamelContext();
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
context.addComponent("experimental", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
context.addRoutes(new RouteBuilder() {
public void configure() {
from("file://test").to("experimental:queue:test");
}
});
context.addRoutes(new RouteBuilder() {
public void configure() {
from("experimental:queue:test").to("stream:out");
}
});
Main main = new Main();
main.getCamelContexts().add(context);
main.run();
}
有没有办法强制 GC 按需清理队列或刷新其内容? 有没有更好的方法使用 Camel 来解决此类问题?
干杯!
最佳答案
您当前正在使用带有 vm 协议(protocol)的 activemq,因此它会在您的进程内创建一个代理。您可以尝试使用外部 activemq 代理吗?如果在这种情况下没有内存泄漏,那么问题出在 activemq 中。不管怎样,vm协议(protocol)主要是为了测试。
关于java - Apache Camel JMS 内存泄漏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11558283/