wood burning stoves 2.0*
The moose likes Other Application Frameworks and the fly likes Beans in Spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Beans in Spring" Watch "Beans in Spring" New topic
Author

Beans in Spring

arnel nicolas
Ranch Hand

Joined: Dec 16, 2003
Posts: 149
Hello there!

Are beans created by the Spring container can be considered thread safe
when instantiated in a Struts action?

arnel
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Whether the beans are thread-safe or not depends on how the beans have been implemented. Having said that, singleton beans are more likely to be non-thread-safe while prototype (non-singleton) beans are more likely to be thread-safe. Still, it's up to what your code does inside the methods that counts.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
arnel nicolas
Ranch Hand

Joined: Dec 16, 2003
Posts: 149
Thanks for the reply. So the bottom line is bean declared singleton cannot be considered thread-safe.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by arnel nicolas:
Thanks for the reply. So the bottom line is bean declared singleton cannot be considered thread-safe.

Not by definition, no. A singleton bean can be thread-safe, but there's no way of knowing that without looking at the code.
Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
Here's a longer discussion of Singletons and Threadsafety.
http://c2.com/cgi/wiki?JavaSingleton
But as said before its no spring issue.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Beans in Spring