Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple ServletContextListner event handling order

 
Lance Miller
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've tried to find this information in the Servlet specification but am not able to. Is the order of the handling of events by multiple configured ServletContextListeners guaranteed? In Tomcat 6.0.26 I've noticed the it seems that initialized events are handled in the same order as the listing of the listeners in the web.xml file. And the destroy events are handled in the reverse order. For example, given the following:



Based on logging, the sequence of events is:


Is this guaranteed by the spec? Or just the way Tomcat is implemented?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a link to the spec in my signature.
For a spec, it's a pretty readable document.
 
Lance Miller
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ben. When I looked in the spec yesterday before posting, I could not find the information. I did find it today. A fresh set of eyes I guess. Anyway, for anyone that finds this thread in the future or is curious, here is the info. The container is suppose to call the listeners in the order they are added during startup, and reverse order during shutdown.

11.3.3 Listener Registration
The Web container creates an instance of each listener class and registers it for event notifications prior to the processing of the first request by the application. The Web container registers the listener instances according to the interfaces they implement and the order in which they appear in the deployment descriptor. During Web application execution, listeners are invoked in the order of their registration.
11.3.4 Notifications At Shutdown
On application shutdown, listeners are notified in reverse order to their declarations with notifications to session listeners preceding notifications to context listeners. Session listeners must be notified of session invalidations prior to context listeners being notified of application shutdown.

(Empahsis Added)
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great.
Thanks for posting back.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic