weld/core — pull request #444 by smoyer64 (2013-12-31 18:26:39+00:00)
Title: Update StartMain.java

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 being called.
- CTRL-C will terminate the program without any @PreDestroy or @Disposes methods being called.
- 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 they're @ApplicationScoped.
- 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 an IllegalStateException.

The problem described in this thread (https://community.jboss.org/thread/180032?start=0&tstart=0) may be related.