Search code examples
javaspringjmsjmstemplate

Spring, Multithreading and jms


Should the JmsTemplate bean be declared as a prototype bean or as a singleton? I think either option is reasonable and it seems to me it's mainly a question of how Spring implemented that bean but I keep finding conflicting reports about the use over the net.


Solution

  • JMSTemplate like most of the spring templates is thread safe after creation so you should leave it at scope singleton.

    If the runnable is implemented as a inner class it can access the instance variables of the class in which you define it. This can be a spring bean with all the required dependencies (jmsTemplate etc) injected into it.