• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Beans in Spring

 
arnel nicolas
Ranch Hand
Posts: 149
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
arnel nicolas
Ranch Hand
Posts: 149
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. So the bottom line is bean declared singleton cannot be considered thread-safe.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2166
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic