I have code that needs to run at application startup and shutdown in my web application. I currently am handling it in servlet. At startup I instantiate some singletons and "initialize" them. At shutdown I have the singletons perform some "clean up" operations.
My question is would it be better to do this with a ServletContextListener? If so, why?