This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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
 
Similar Threads
Eclipse error : Declared package does not match expected package
Aliasing in Spring
Can't use spring security authorize
Are spring beans thread-safe?
singleton in spring bean