Ittai
Ittai

Reputation: 5915

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.

Upvotes: 1

Views: 2433

Answers (1)

gkamal
gkamal

Reputation: 21000

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.

Upvotes: 3

Related Questions