Author: markt Date: Thu Nov 5 22:08:30 2009 New Revision: 833211 URL: http://svn.apache.org/viewvc?rev=833211&view=rev Log: Apply Filip's suggestion to improve concurrency
Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java?rev=833211&r1=833210&r2=833211&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java (original) +++ tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java Thu Nov 5 22:08:30 2009 @@ -1280,84 +1280,48 @@ * @exception ClassNotFoundException if the class was not found */ @Override - public synchronized Class<?> loadClass(String name, boolean resolve) + public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { - if (log.isDebugEnabled()) - log.debug("loadClass(" + name + ", " + resolve + ")"); - Class<?> clazz = null; - - // Log access to stopped classloader - if (!started) { - try { - throw new IllegalStateException(); - } catch (IllegalStateException e) { - log.info(sm.getString("webappClassLoader.stopped", name), e); - } - } - - // (0) Check our previously loaded local class cache - clazz = findLoadedClass0(name); - if (clazz != null) { - if (log.isDebugEnabled()) - log.debug(" Returning class from cache"); - if (resolve) - resolveClass(clazz); - return (clazz); - } - - // (0.1) Check our previously loaded class cache - clazz = findLoadedClass(name); - if (clazz != null) { + synchronized (name.intern()) { if (log.isDebugEnabled()) - log.debug(" Returning class from cache"); - if (resolve) - resolveClass(clazz); - return (clazz); - } - - // (0.2) Try loading the class with the system class loader, to prevent - // the webapp from overriding J2SE classes - try { - clazz = system.loadClass(name); + log.debug("loadClass(" + name + ", " + resolve + ")"); + Class<?> clazz = null; + + // Log access to stopped classloader + if (!started) { + try { + throw new IllegalStateException(); + } catch (IllegalStateException e) { + log.info(sm.getString("webappClassLoader.stopped", name), e); + } + } + + // (0) Check our previously loaded local class cache + clazz = findLoadedClass0(name); if (clazz != null) { + if (log.isDebugEnabled()) + log.debug(" Returning class from cache"); if (resolve) resolveClass(clazz); return (clazz); } - } catch (ClassNotFoundException e) { - // Ignore - } - - // (0.5) Permission to access this class when using a SecurityManager - if (securityManager != null) { - int i = name.lastIndexOf('.'); - if (i >= 0) { - try { - securityManager.checkPackageAccess(name.substring(0,i)); - } catch (SecurityException se) { - String error = "Security Violation, attempt to use " + - "Restricted Class: " + name; - log.info(error, se); - throw new ClassNotFoundException(error, se); - } + + // (0.1) Check our previously loaded class cache + clazz = findLoadedClass(name); + if (clazz != null) { + if (log.isDebugEnabled()) + log.debug(" Returning class from cache"); + if (resolve) + resolveClass(clazz); + return (clazz); } - } - - boolean delegateLoad = delegate || filter(name); - - // (1) Delegate to our parent if requested - if (delegateLoad) { - if (log.isDebugEnabled()) - log.debug(" Delegating to parent classloader1 " + parent); - ClassLoader loader = parent; - if (loader == null) - loader = system; + + // (0.2) Try loading the class with the system class loader, to prevent + // the webapp from overriding J2SE classes try { - clazz = Class.forName(name, false, loader); + clazz = system.loadClass(name); if (clazz != null) { - if (log.isDebugEnabled()) - log.debug(" Loading class from parent"); if (resolve) resolveClass(clazz); return (clazz); @@ -1365,36 +1329,53 @@ } catch (ClassNotFoundException e) { // Ignore } - } - - // (2) Search local repositories - if (log.isDebugEnabled()) - log.debug(" Searching local repositories"); - try { - clazz = findClass(name); - if (clazz != null) { + + // (0.5) Permission to access this class when using a SecurityManager + if (securityManager != null) { + int i = name.lastIndexOf('.'); + if (i >= 0) { + try { + securityManager.checkPackageAccess(name.substring(0,i)); + } catch (SecurityException se) { + String error = "Security Violation, attempt to use " + + "Restricted Class: " + name; + log.info(error, se); + throw new ClassNotFoundException(error, se); + } + } + } + + boolean delegateLoad = delegate || filter(name); + + // (1) Delegate to our parent if requested + if (delegateLoad) { if (log.isDebugEnabled()) - log.debug(" Loading class from local repository"); - if (resolve) - resolveClass(clazz); - return (clazz); + log.debug(" Delegating to parent classloader1 " + parent); + ClassLoader loader = parent; + if (loader == null) + loader = system; + try { + clazz = Class.forName(name, false, loader); + if (clazz != null) { + if (log.isDebugEnabled()) + log.debug(" Loading class from parent"); + if (resolve) + resolveClass(clazz); + return (clazz); + } + } catch (ClassNotFoundException e) { + // Ignore + } } - } catch (ClassNotFoundException e) { - // Ignore - } - - // (3) Delegate to parent unconditionally - if (!delegateLoad) { + + // (2) Search local repositories if (log.isDebugEnabled()) - log.debug(" Delegating to parent classloader at end: " + parent); - ClassLoader loader = parent; - if (loader == null) - loader = system; + log.debug(" Searching local repositories"); try { - clazz = Class.forName(name, false, loader); + clazz = findClass(name); if (clazz != null) { if (log.isDebugEnabled()) - log.debug(" Loading class from parent"); + log.debug(" Loading class from local repository"); if (resolve) resolveClass(clazz); return (clazz); @@ -1402,9 +1383,30 @@ } catch (ClassNotFoundException e) { // Ignore } + + // (3) Delegate to parent unconditionally + if (!delegateLoad) { + if (log.isDebugEnabled()) + log.debug(" Delegating to parent classloader at end: " + parent); + ClassLoader loader = parent; + if (loader == null) + loader = system; + try { + clazz = Class.forName(name, false, loader); + if (clazz != null) { + if (log.isDebugEnabled()) + log.debug(" Loading class from parent"); + if (resolve) + resolveClass(clazz); + return (clazz); + } + } catch (ClassNotFoundException e) { + // Ignore + } + } + + throw new ClassNotFoundException(name); } - - throw new ClassNotFoundException(name); } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org