I have a standalone Java application that acts as a consumer that connects to an ActiveMQ queue. In my application's main()
method, I create an instance of the consumer as a thread and start it.
Seeing that I'm using JMS for this, I want to add a shutdown hook to my application so that when my application stops working (either terminated or killed), my application would run some method wherein all my resources will be closed.
I already tried Runtime.addShutdownHook()
but it doesn't seem to be invoked whenever I shut down my application.
I would like it to act as if the contextDestroyed()
method of a ServletContextListener
was invoked.