This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Spring and the fly likes Are the singleton objects created from Spring beans  in the same way as there is SingleThreadModel? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Are the singleton objects created from Spring beans  in the same way as there is SingleThreadModel?" Watch "Are the singleton objects created from Spring beans  in the same way as there is SingleThreadModel?" New topic
Author

Are the singleton objects created from Spring beans in the same way as there is SingleThreadModel?

Monica Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 820
Are the singleton objects created from Spring beans in the same way as there is SingleThreadModel where only thread can access at once? Since in Spring only 1 object of are created from the beans, if multiple threads try to access the application then wont the case be like SingleThreadModel servlets?

thanks
Jayesh A Lalwani
Saloon Keeper

Joined: Jan 17, 2008
Posts: 2683
    
  31

No multiple threads will access the same singleton object. It won't be like the SIngleThreadedModel, unless you synchronize your methods yourself.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17276
    
    6

Basically, if you have a stateless object. Then a single instance can run with as many threads as your Operating System allows. Each thread can run the same method in the same instance all simultaneously without any problems

Problems only occur when your object is holding state. Meaning it has instance variables that each thread might change to different values. but 99.99% of your beans you configure in Spring will be stateless classes like your Service and Repository classes. If you find you ahve object holding state that you want as Spring Beans, look at your design and you will see a code smell there.

Mark


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Monica Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 820
Thanks..i got the point..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Are the singleton objects created from Spring beans in the same way as there is SingleThreadModel?
 
It's not a secret anymore!