• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 842
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is good link

http://www.mkyong.com/spring/spring-bean-scopes-examples/
 
Ranch Hand
Posts: 79
Eclipse IDE Spring Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found a good post on this http://knowledgesun.com/difference-between-springs-singleton-and-javas-singleton/.
This explain various differences with examples:
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic