Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Spring and the fly likes what is the difference between singleton and global session spring bean scopes ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "what is the difference between singleton and global session spring bean scopes ?" Watch "what is the difference between singleton and global session spring bean scopes ?" New topic
Author

what is the difference between singleton and global session spring bean scopes ?

Myke Enriq
Ranch Hand

Joined: Feb 13, 2012
Posts: 109
Singleton is one per container , global session is one per global session per container.

As I have never used global session beans , I can not help but wonder what the difference is.
sai rama krishna
Ranch Hand

Joined: May 29, 2009
Posts: 245
Here is good link

http://www.mkyong.com/spring/spring-bean-scopes-examples/
Rohit Mehta
Ranch Hand

Joined: Mar 11, 2005
Posts: 79

Though related, Singleton pattern is described at per class loader level.
Singleton bean scope is per spring container.

http://www.javabench.in/2012/04/difference-between-singleton-design.html


- Rohit
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2342
    
  28

In Spring there is always one instance of a singleton bean per container

The J2EE specification introduces the concept of session. A session is associsciated with a user session. Since, HTTP is stateless, the web containers use either cookies or url parameters to identify that the requests coming in belong to an user that the server has seen before. In Spring, in a web application, a session scoped bean is tied to the HTTP Session. SO, there is an instance of the bean per HTTP session.

With Portlets, J2EE introduces the concept of Portlet Session. A web application contains portlets. Each portlet is given access to a Portlet Session. A Portlet Session works very similarly to HTTP Session, except that the Portlet Session has 2 scopes; Portlet Scope and Application scope. If you use Spring in an portlet application, then a session scoped bean is tied to the Portlet Scope. A global session scoped bean is tied to the application scope

Now, I'm pretty sure that both session scoped beans and globabl session scoped beans are tied to the underlying Portlet Session. So, if you have 2 Spring containers inside a portlet, they will end up sharing the beans. I'm pretty sure, but not certain. You might want to try it out to make sure. I'm looking at the Spring's code here and it looks to be that the bean is simply retreived from the underlying PortletSession.

I'm pretty sure global session scoped beans are one per global session, and not one per global session per container
 
Consider Paul's rocket mass heater.
 
subject: what is the difference between singleton and global session spring bean scopes ?