Announcement Announcement Module
Collapse
No announcement yet.
shutdown on DefaultMessageListenerContainer block my thread Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • shutdown on DefaultMessageListenerContainer block my thread

    Hi, i'm using the Spring 2.5.2 and ActiveMQ 4.1.1 and encounter problems while tying to shutdown a DefaultMessageListenerContainer.

    Here is what I am doing:
    Code:
    // Starts the container
    mdpContainer = new DefaultMessageListenerContainer();
    jmsManagedCpeInstanceMDP = new JmsManagedCpeInstanceMDP();
    jmsManagedCpeInstanceMDP.setMyContainer(mdpContainer);
    mdpContainer.setAutoStartup()
    mdpContainer.setMessageListener(jmsManagedCpeInstanceMDP);
    mdpContainer.setSessionTransacted(true);
    mdpContainer.afterPropertiesSet();
    mdpContainer.start();
    mdpContainer.waitUntilStarted();
    I want to close my container by calling the shutdown() method inside my MDP jmsManagedCpeInstanceMDP (in fact the container must be shutdown when the MDP receive a special JMS message).

    Code:
    this.cpeToServerSender.sendJvmNotificationMessage(JvmState.IS_TERMINATED);     // sends a JMS message
    myContainer.shutdown();
    The process which executes the myContainer Spring container blocks on the shutdown() call.
    Do you know why ?
    Am i doing something wrong when tying to shutdown the container ?

    This problem appear in a JUnit test, so i'm not running the code inside a application server for the moment.

    Thanks.

    Baptiste.

  • #2
    I setup the container like this and it works fine


    ....
    Code:
                    DefaultMessageListenerContainer listenerContainer = new DefaultMessageListenerContainer();
    		listenerContainer.setAutoStartup(true);
    		listenerContainer.setMessageListener(listener);
    		listenerContainer.setConnectionFactory(factory);
    		listenerContainer.setDestination(destination);
    		listenerContainer.setRecoveryInterval(recoveryInterval);
    		listenerContainer.setPubSubDomain(true);
    		listenerContainer.setAcceptMessagesWhileStopping(false); // i guess this is the required setting to avoid the blocking behaviour
    		listenerContainer.setTransactionName(transactionModeStr);
    		PlatformTransactionManager manager = environmenAccess.getTransactionManager(destinationName, typeOfMessage, parameter);
    		if (manager != null)
    			listenerContainer.setTransactionManager((PlatformTransactionManager) manager);
    listenerContainer.afterPropertiesSet();
    			listenerContainer.start();
    			getListenerContainers().add(listenerContainer);
    you can leave out the Transaction Manager stuff.

    To shutdown i use following code

    Code:
    public void shutDownListeners() throws Exception {
    		for (DefaultMessageListenerContainer container : getListenerContainers()) {
    			try {
    				container.shutdown();
    				container.destroy();
    			} catch (Exception exc) {
    				if (logger.isDebugEnabled())
    					logger.debug("Error shutting down ListnerContainer", exc);
    			}
    		}

    Comment

    Working...
    X