• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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.
 
Let nothing stop you! Not even this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic