Results 1 to 2 of 2

Thread: shutdown on DefaultMessageListenerContainer block my thread

  1. #1
    Join Date
    Aug 2007
    Location
    Paris
    Posts
    25

    Default 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. #2

    Default

    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);
    			}
    		}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •