【发布时间】:2014-10-27 16:16:56
【问题描述】:
我有一个简单的 Spring Integration 应用程序,它在 Tomcat (v7.0.x) 上运行并使用 Websphere MQ 队列中的消息。当我从 Tomcat 服务器取消部署 WAR 时,WAR 可以取消部署,但是 JMS 侦听器线程仍在 Tomcat 服务器上运行,该线程仍将使用 Websphere MQ 队列中的消息。因此,我假设我没有正确处理 JMS 侦听器清理应用程序的一部分?
这是我正在使用的堆栈:
Java 8
Tomcat 7.0.55
Spring Integration 4.0.4
Spring Integration Java Dsl 1.0.0.M3
就我的 SI 应用程序的配置而言,我有一个 JmsConfig 类:
@Configuration
@ComponentScan
public class JmsConfig {
@Autowired
private Properties jndiProperties;
private ConnectionFactory mqConnectionFactory() throws NamingException {
Context ctx = new InitialContext(jndiProperties);
try {
MQQueueConnectionFactory connectionFactory = (MQQueueConnectionFactory)
ctx.lookup("jms/service/SERVICE_QCF");
return connectionFactory;
} finally {
ctx.close();
}
}
@Bean
public ConnectionFactory cachingConnectionFactory() throws NamingException {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
connectionFactory.setTargetConnectionFactory(mqConnectionFactory());
connectionFactory.setSessionCacheSize(10);
return connectionFactory;
}
}
我有一个集成配置类:
@Configuration
@EnableIntegration
public class IntegrationConfig {
@Autowired
private ConnectionFactory cachingConnectionFactory;
@Bean
public IntegrationFlow requestFlow() {
return IntegrationFlows
.from(Jms.inboundAdapter(cachingConnectionFactory).destination(
"SERVICE_QUEUE_NAME"), c -> {
c.poller(Pollers.fixedRate(100));
})
.channel("request.service.ch").get();
}
}
Web Initialiser 配置类:
@Configuration
public class WebInitialiser implements WebApplicationInitializer {
public void onStartup(ServletContext servletContext)
throws ServletException {
AnnotationConfigWebApplicationContext rootContext =
new AnnotationConfigWebApplicationContext();
rootContext.register(ApplicationConfig.class, JmsConfig.class,
IntegrationConfig.class, DatabaseConfig.class);
servletContext.addListener(new ContextLoaderListener(rootContext));
}
}
在取消部署阶段,我在 catalina 日志中看到以下可能相关或不相关的内容:
SEVERE: The web application [/service-a] appears to have started a thread named [Thread-7] but has failed to stop it. This is very likely to create a memory leak.
为了确保在 WAR 的取消部署阶段从 Tomcat 的 JVM 中清除部署的 JMS 侦听器线程,是否有任何我尚未设置、配置或注释的内容?
提前致谢, 下午。
【问题讨论】:
标签: spring tomcat7 ibm-mq spring-integration spring-jms