It's absolutely silly, but the issue has gone away after I rebooted my machine :) I am running Windows 7, Oracle JDK 1.6/1.7, Tomcat 6/7, the problem persisted for any combination of these. The profiler was showing me that it was sun.net.www.protocol.jar.URLJarFile
's <init>
which was slowing down the whole stuff. Probably something went wrong with jars cache so that unnecessary initialization executed for every class requested from a jar.
Update: I've found how to fix the issue with class loading being so slow and getting even slower as long as you are not rebooting your machine. Instead of using
new URL("jar:file:/D:/Work/temp/jars/antlr-2.7.7.jar!/")
I've tried
new URL("file:/D:/Work/temp/jars/antlr-2.7.7.jar")
The URLClassloader
handles properly this kind of URLs as jars even without "jar" protocol being specified. However it drastically increased the performance! Still I don't know the exact reason for this behavior.