Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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

 
Ranch Hand
Posts: 1545
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No multiple threads will access the same singleton object. It won't be like the SIngleThreadedModel, unless you synchronize your methods yourself.
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Monica Shiralkar
Ranch Hand
Posts: 1545
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks..i got the point..
 
    Bookmark Topic Watch Topic
  • New Topic