I know what ServletContextListener is and how to implement/register it in web.xml.
But the question is the following. At the start of web application single instance of listener per javaVM is created. Then its contextInitialized() method is called.
At the moment when application is being closed, contextDestroyed() method of listener is called. But is it the same instance of listener? Or that first instance could be destroyed and new one created for contextDestroyed() call?
Definitive proof would have to come from the Servlet spec. I’m not sure that it provides an explicit answer to your question, but it does provide a strong hint:
Which implies that creating instances after processing the first request is prohibited.