Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

scope: session vs application

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I can't figure out the real difference of session scope and application scope...
When I should use the two scopes? Could someone give me an example of an application that I'd have to use both two scope?
 
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Session scope is for data related to a particular client session, for example a Shopping Basket.
Application scope is for data that can be shared between clients.
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Practical things that I've been using application scope for include:
  • Configuration information such as the URL for resources living on a different server, so that a JSP can easily access this information. For example, this statistics server maintains a reference to the parent site in this way.
  • Shared objects such as caches. If you need some sort of Singleton in a web application, you could well be better off using the application context rather than a static variable for the purpose. When a class is reloaded, and you're using a static variable, you suddenly have two instances of your Singleton. This usually happens during development, but can also bite you when hot-patching production systems. Beware of ClassCastExceptions after a class has been reloaded!
  • If you have a dynamic, pluggable application, the application context is a good place to stuff factory objects.
  • Note -- while thread safety is important for session-scoped objects, it is doubly so for application-scoped objects.
    - Peter
    [ November 13, 2002: Message edited by: Peter den Haan ]
     
    Are you here to take over the surface world? Because this tiny ad will stop you!
    free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
    https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
    reply
      Bookmark Topic Watch Topic
    • New Topic