I think the ServletContextListener is more appropriate for a web application, because you clean up resources for each and every session.
A shutdown hook is executed with the JVM is shut down. That would be when you stop your container, which is a one-time event.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…