简体   繁体   中英

Cannot undeploy from Tomcat due to specific Spring JMS configuration

I have used ActiveMQ as JMS implementation ( activemq-spring 5.12.1 ) and Spring JMS integration ( spring-jms 4.2.3.RELEASE ), all wrapped in Spring Boot web application, being deployed on Tomcat.

I have following Spring configuration (code reduced for the verbosity of code sample):

@Configuration
@EnableJms
public class AppConfiguration {
    @Bean
    public XAConnectionFactory jmsXaConnection(String activeMqUsername, String activeMqPassword) {
        ActiveMQXAConnectionFactory activeMQXAConnectionFactory = new ActiveMQXAConnectionFactory(activeMqUsername, activeMqPassword, activeMqUrl);
        ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy();
        prefetchPolicy.setAll(0);
        activeMQXAConnectionFactory.setPrefetchPolicy(prefetchPolicy);
        return activeMQXAConnectionFactory;
    }

    @Bean
    public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(ConnectionFactory connectionFactory, JtaTransactionManager jtaTransactionManager) {
        DefaultJmsListenerContainerFactory containerFactory = new DefaultJmsListenerContainerFactory();
        containerFactory.setConnectionFactory(connectionFactory);
        containerFactory.setTransactionManager(jtaTransactionManager);
        containerFactory.setSessionTransacted(true);
        containerFactory.setTaskExecutor(Executors.newFixedThreadPool(2));
        containerFactory.setConcurrency("2-2");
        containerFactory.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONSUMER);
        return containerFactory;
    }
}

My target was to configure two consumers (hence concurrecny set to 2-2) and to prevent any messages caching (hence prefetch policy set to 0).

It works, but causes very unpleasent side effect: When I try to undeploy the application via Tomcat Manager, it hangs for a while and then indefinitely, every second produces following DEBUG message:

"DefaultMessageListenerContainer:563 - Still waiting for shutdown of 2 Message listener invokers" .

Therefore, I am forced to kill Tomcat process every time. What have I done wrong?

One of my lucky shots (documentation both ActiveMQ and Spring JMS was not that helpful), was to set prefetch policy to 1 instead of 0. Then it undeploys gracefully, but I cannot see how it can relate.

Also I am curious, why having cache level set to CACHE_CONSUMER is required for the ActiveMQ to create two consumers. When default setting was left ( CACHE_NONE while using external transaction manager), only one consumer was created (while concurrency was still set two 2-2, and so was TaskExecutor ).

If it matters, for connection factory and transaction manager, Atomikos is used. I can paste its configuration also, but it seems irrelevant.

Most likely this means the consumer threads are "stuck" in user code; take a thread dump with jstack to see what the container threads are doing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM