• Post Reply Bookmark Topic Watch Topic
  • New Topic

When to use scope=application?

 
Sarada Bhasker
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • 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.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • 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
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • 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).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!