Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Singleton Design Pattern and Singleton Spring Bean

 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic