title: URLClassLoader slow under Tomcat
body: <p>I have a classpath directory containing about 30 jars. In my plain console application I am creating an <code>URLClassLoader</code> where I initialize it with the list of <code>URL</code>s pointing to all these jars.</p>
  
  <pre><code>URL[] urls = new URL[] {
      new URL("jar:file:/D:/Work/temp/jars/antlr-2.7.7.jar!/"),
      new URL("jar:file:/D:/Work/temp/jars/aopalliance-1.0.jar!/"),
      new URL("jar:file:/D:/Work/temp/jars/c3p0-0.9.1.jar!/"),
      ...
  }
  URLClassLoader cl = new URLClassLoader(urls, getClass().getClassLoader());
  Class&lt;?&gt; c = cl.loadClass(...);
  etc...
  </code></pre>
  
  <p>Like this everything is working fine, taking a few milliseconds to load a single class from my <code>URLClassLoader</code>.</p>
  
  <p>Now I take this snippet of code and make it run under Tomcat, e.g. triggered at a simple web request inside a servlet's <code>doGet()</code>. Surprisingly, the time lapse taken to load an average class becomes 10-15 times longer, making the whole initialization time inacceptable. The issue holds for at least Tomcat versions both 6 and 7.</p>
  
  <p>Any ideas?</p>