Author: Steve Moyer <smoyer64(a)gmail.com>
Date: 2014-01-02 (Thu, 02 Jan 2014)
WELD-1579: Weld-SE's shutdown hook fails to dispose of CDI managed objects
The shutdown hook needs to be registered with the JVM before the Weld container is
initialized. Without the shutdown hook, the following problems occur (or can occur):
- System.exit(0) will terminate the program without any @PreDestroy or @Disposes methods
- CTRL-C will terminate the program without any @PreDestroy or @Disposes methods being
- SIGTERM will terminate the program without any @PreDestroy or
@Disposes methods being called.
- Normal completion of methods that @Observes the ContainerInitialized events (effectively
the program's entry points) will not call @PreDestroy or @Disposes methods unless
- Since calling addShutdownHook() is not permitted once the JVM has started the shutdown
process, multi-threaded applications can allow the main thread to return to StartMain
while the JVM is still running. Executing addShutdownHook() in this instance will throw
The problem described in this thread
) may be related.