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.
Asked
Active
Viewed 2,359 times
1

Ittai
- 5,625
- 14
- 60
- 97
-
Sorry, you are asking at least 5 questions at once, mixed with your own opinions. There's no good way to answer that. I'm voting to close. Ask 2 or 3 more specific questions, and you'll get answers. – Sean Patrick Floyd Sep 09 '11 at 14:45
-
@Sean Patrick Floyd It's possible you're right and I did not break down the question correctly. I actually see two questions here, multithreading and jmstemplate, can you please say what the questions are (not in detail of course) so I will not repeat the mistake? BTW, for my own defence, I did think of breaking it down but thought that only part of the picture would make the question less understandable. – Ittai Sep 09 '11 at 14:49
1 Answers
3
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.

gkamal
- 20,777
- 4
- 60
- 57
-
Thanks for your answer. I think I'll take up Sean's suggestion and separate the questions so this question will be about JMSTemplate and I'll mark your answer as correct. I'd appreciate it if you could "follow me" to the next question: http://stackoverflow.com/questions/7365971/spring-and-multithreading Thanks – Ittai Sep 09 '11 at 18:33