• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How does Spring singleton beans handle too much traffic?

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I know that Spring beans in application context are singletons by default. So how does the framework handles the singleton structure when there is too much traffic. For example, if I have bean named daoManager for accessing database and its singleton. And if there are too many users accessing the database layer, then the single instance of daoManager will probably get slowed. So how does spring handles this situation? Does it create a new instance of the daoManager or it will just die out?

Thanks in advance.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nope. Traffic has no impact on the object. If the DAO doesn't hold any state, which it shouldn't. Then it is all based on how many threads the OS can handle. And Another wait point could be your Connection Pool setting. But regardless of both those has absolutely no affect on the Spring bean. It can handle as many threads all at once.

If your bean is holding state, then you have thread issues because more than one thread could be changing that state, then you have to do synchronization. That is why you should have the DAO hold state.

Mark
 
Fawad Ali
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mark:
Thanks for your replies. My concern is that if I have a function named getABC() in a singleton bean. If it is invoked for user A and it takes a processing time close to infinity(too many loops etc). Then the second user B will have to wait until the user A request is not finished. Is it like that?

This may not be a question related to Spring but to singleton pattern but as I have started the thread here so let me ask you this.

Once again, thanks for your response.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Fawad Ali wrote:Mark:
Thanks for your replies. My concern is that if I have a function named getABC() in a singleton bean. If it is invoked for user A and it takes a processing time close to infinity(too many loops etc). Then the second user B will have to wait until the user A request is not finished. Is it like that?



Not at all. Each user can call the same method at the exact same time and all run simultaneously. Each user gets their own thread of execution.

Mark
 
Fawad Ali
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow, Thats amazing. I didnt know singleton does that. How dumb I am.

Thanks a lot.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Fawad Ali wrote:Wow, Thats amazing. I didnt know singleton does that. How dumb I am.

Thanks a lot.



Has nothing to do with Singleton. Has to do with a Java object. I can have an instance and if that object doesn't hold state, I don't have any threading issues.

Mark
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic