File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes Question on Singleton Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Question on Singleton" Watch "Question on Singleton" New topic

Question on Singleton

Rahul Sud

Joined: May 27, 2008
Posts: 25
Hi Techies,

We know that Spring is by default singleton.
Now the question is How it will behave when more than two request comes at same time on the same method.How that will be handled in the by Spring.
I suppose same instance will be shared but what is the normal approach to handle that.I mean the JVM behavior for this also.


David Newton

Joined: Sep 29, 2008
Posts: 12617

"How to handle it" depends on what it's actually doing. If there's no shared state and you're just calling methods with only parameters and local variables, there's nothing to do. If you're reading shared state that might change, or mutating shared state, something somewhere along the line would need to be synchronized, whether it's a simple collection, and entire method, etc. Totally depends.
I agree. Here's the link:
subject: Question on Singleton
It's not a secret anymore!