title: What is eager loading in Java?
body: <p>I have come across eager loading in Java in two classes of Spring <code>NestedRuntimeException</code> and <code>AbstractApplicationContext</code>, both of these cases resolve the same Class loader issue using static code block, but the way they are used is confusing.</p>
  
  <p>The confusion is regarding the call to <code>ClassName.class.getName()</code> in static code block, how does this resolve class loader issue.</p>
  
  <pre><code>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();
      }
  </code></pre>
  
  <p>If I were to do this same, I would get the class loader and load this class manually</p>
  
  <pre><code>Thread.currentThread()
  .getContextClassLoader().loadClass(ContextClosedEvent.class.getName());
  
  </code></pre>
  
  <p>Any expert advice will be appreciated.</p>
  
  <p><a href="https://github.com/spring-projects/spring-framework/issues/10278" rel="nofollow noreferrer">Reference</a></p>