I have come across eager loading in Java in two classes of Spring NestedRuntimeException
and AbstractApplicationContext
, both of these cases resolve the same Class loader issue using static code block, but the way they are used is confusing.
The confusion is regarding the call to ClassName.class.getName()
in static code block, how does this resolve class loader issue.
static {
// Eagerly load the ContextClosedEvent class to avoid weird classloader issues
// on application shutdown in WebLogic 8.1. (Reported by Dustin Woods.)
ContextClosedEvent.class.getName();
}
If I were to do this same, I would get the class loader and load this class manually
Thread.currentThread()
.getContextClassLoader().loadClass(ContextClosedEvent.class.getName());
Any expert advice will be appreciated.