aspose file tools*
The moose likes Spring and the fly likes Singleton Design Pattern and Singleton Spring Bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Singleton Design Pattern and Singleton Spring Bean" Watch "Singleton Design Pattern and Singleton Spring Bean" New topic
Author

Singleton Design Pattern and Singleton Spring Bean

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

Guys,

The doubt that I have is, is the Singleton Design Pattern and the Singleton Bean in Spring are the same or different. I just googled for this and some posts say that they are totally different. Any thoughts on this as well?


SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

Are there new threads that are spawned for each requests to the Singleton bean in Spring? Something like the service method in Servlets???
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'm not sure what a "request to a singleton bean" is.

A singleton bean follows the singleton pattern--there's only one instance.

I guess I'm not really sure what you're asking.
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
They are quite different.
GoF Singleton class will have only one instance per ClassLoader, whereas for Spring Singleton the only one instance will be created per container and per bean.


SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
Jothi Shankar Kumar wrote:Are there new threads that are spawned for each requests to the Singleton bean in Spring? Something like the service method in Servlets???

It depends on that you (or servlet container or any code) create a new thread or not. Spring Framework doesn't create new thread.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

Kengkaj Sathianpantarit wrote:
Jothi Shankar Kumar wrote:Are there new threads that are spawned for each requests to the Singleton bean in Spring? Something like the service method in Servlets???

It depends on that you (or servlet container or any code) create a new thread or not. Spring Framework doesn't create new thread.


What do you mean here? If I need I can create a new servlet thread?? The servlet specification says that for each request, the container creates a new thread starting from the service method. So I though for the Singleton Spring beans, Spring would be doing something like that...
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
Jothi Shankar Kumar wrote:
Kengkaj Sathianpantarit wrote:
Jothi Shankar Kumar wrote:Are there new threads that are spawned for each requests to the Singleton bean in Spring? Something like the service method in Servlets???

It depends on that you (or servlet container or any code) create a new thread or not. Spring Framework doesn't create new thread.


What do you mean here? If I need I can create a new servlet thread?? The servlet specification says that for each request, the container creates a new thread starting from the service method. So I though for the Singleton Spring beans, Spring would be doing something like that...

I mean if servlet container create a new thread, there will be a new thread. Spring doesn't create a new thread.

I just rephrase my answer. I wonder what makes you think Spring will create a new thread.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Singleton Design Pattern and Singleton Spring Bean
 
Similar Threads
Spring -> Factory Design Pattern / IOC/DI ?
Spring core container is the basis for complete Spring framework?
Singleton Creation
Information about Design Patterns used by Spring.
singleton in spring bean