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

ContextListener

 
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have two servlets TestServlet and TestServlet2 in a web-app along with a <listenter>LifecycleListener</listener> defined in web.xml. Also both servlets are configured to load on startup. It seems like only one instance of the listenter instance is created.
What is the life cycle of a web-app listener. One instance for all the servlets? Thanks.
 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Define in web.xml
<listener>
<listener-class>TestServlet1</listener-class>
</listener>
<listener>
<listener-class>TestServlet2</listener-class>
</listener>

//javax.servlet.ServletContextListener interface is notified when web application is initialed or destroyed in container
***you remeber :
one context per web application per JVM
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
the web server creates one instance per <listener-class> included in the web.xml.
According to the servlet specifications the instantiation process has to be completed prior to executing the first request for the application.
Also, the container must maintain a handle to the listener until the last request is made.
 
We begin by testing your absorbancy by exposing you to this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic