I am new in Spring Framework and my questions are below:

I want to instantiate the DefaultMessageListenerContainer programmatically and the code that I use is:

DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
container.setConnectionFactory(cf);
container.setDestination(Queue);
container.setMessageListener(Consumer);
container.setReceiveTimeout(-1);
container.setMaxConcurrentConsumers(15);
container.setConcurrentConsumers(10);
container.start();

Why do I have to shutdown manually the DefaultMessageListenerContainer when my project is undeployed? If i do not shutdown manually the container the consumers stay open on my queues.

When I try to shutdown manually the container (by calling container.shutdown()) the procedure stucks and the project does not continue. If i initialize the DefaultMessageListenerContainer without giving "receiveTimeout" the shutdown procedure is executed correctly. Is there any problem with setReceiveTimeout(-1)?