wood burning stoves 2.0*
The moose likes Spring and the fly likes How does Spring singleton beans handle too much traffic? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "How does Spring singleton beans handle too much traffic?" Watch "How does Spring singleton beans handle too much traffic?" New topic
Author

How does Spring singleton beans handle too much traffic?

Fawad Ali
Ranch Hand

Joined: Dec 28, 2009
Posts: 112
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.


Regards, Fawad Ali.
Software Engineer, Stafona Inc. - My Blog
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Fawad Ali
Ranch Hand

Joined: Dec 28, 2009
Posts: 112
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
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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

Joined: Dec 28, 2009
Posts: 112
Wow, Thats amazing. I didnt know singleton does that. How dumb I am.

Thanks a lot.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How does Spring singleton beans handle too much traffic?
 
Similar Threads
Spring Vs EJB
Spring Controllers singleton or not?
Singleton Creation
Session swapping problem under load
Spring Vs EJB