I’m trying to write a multithreaded implementation for JMS message processing from a queue.
I’ve tried with DefaultMessageListenerContainer and SimpleMessageListenerContainer classes.
The problem I have is that it seems like just a single instance of the MessageListener class gets ever instantiated, no matter how I configure it. This forces me to unnecessarily write stateless or thread-safe MessageListener implementations, since I have the ListenerContainer configured to use multiple threads (concurrentConsumers=8).
Is there an obvious solution to this that I’m overlooking?
This is by design. The
MessageListeneris a dependency that you inject into Spring – it has no way of instantiating new ones.You make that sound like a bad thing. Making your
MessageListeneris a very good idea, Spring just removes the temptation to do otherwise.