In Tomcat, when the server closes, it tries to set all the static variables in the classes that it knows about to be equal to zero. Touching these classes, their static initializers are launched, which can lead to an endless loop for some of our deprecated classes that have massive static initializers.
Is there an elegant way to determine if a shutdown is complete? Then we could check at the top of the static initializers if we are in shutdown mode and then ignore the initialization.
The only way we work with is nothing but elegant:
try{ Thread hook = new Thread(); Runtime.getRuntime().addShutdownHook( hook ); // fires "java.lang.IllegalStateException: Shutdown in progress" if currently in shutdown Runtime.getRuntime().removeShutdownHook( hook ); }catch(Throwable th){ throw new Error("Init in shutdown thread", th ); }
Epaga
source share