• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

When to use scope=application?

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,
I am confused about using the scope attributes sesion and application. I am using HttpSession objects and at the moment I am using scope=session. I would like to know when should I use scope=application. Many books say that when scope=application the session objects are available until the application is running. But what I don't understand is when does the application stops running in the case of JSP's.
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sarada Bhasker:
[...] I would like to know when should I use scope=application. [...] But what I don't understand is when does the application stops running in the case of JSP's.


In terms of visibility, application scope means that every page or servlet in the application has access to that very same object (which immediately implies that it needs to be carefully synchronized indeed). In terms of lifetime, while session objects expire when the session times out, application scoped objects live "forever" (as long as the application lives, or until you clear them).
The application stops only when you shut down (or crash ) the server, or when you explicitly stop the application using a server management tool.
- Peter
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is like global variables for all jsps and servlets. If you have any values which you want to share among all servlets and jsps of one web-appln then application scope is better suitable. Most people create DB Connection Pool in one of servlet's init(,..) method and put it in servletContext/application scope so that there will be single connection pool object commonly known and shared among all servlets and jsps of that particular web application.
regds
maha anna
[This message has been edited by maha anna (edited April 21, 2001).]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic