my dog learned polymorphism*
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 Murach's Java Servlets and JSP this week in the Servlets 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
Similar Threads
Singleton Design Pattern and Singleton Spring Bean
List of Pending assignments in my queue
Instantiating a Bean in Spring
singleton in spring bean
jquery, hover and unbind