@PreDestroy is not called for CDI managed objects when the JVM calls the Weld SE ShutdownHook. Issue #1579 fixed this during 2.1 development and my limited testing shows that it's still working in the latest 2.2 release. As noted, it doesn't work at all in 2.3.0.CR1 or 3.0.0.Alpha11.
During my testing I discovered a second problem with container shutdown and I suspect this problem will also exist when calling shutdown() programatically. Objects that are dynamically instantiated by the container don't seem to be properly disposed. Objects created by the following code will not have their @PostConstruct methods called on shutdown: { { code} OtherThread otherThread = CDI.current().select(OtherThread.class).get(); {code } } for Versions up through 2.2.15, object created by the following code will have their @PostConstruct methods called on shutdown: { { code} @Inject OtherThread otherThread_; {code } }
|