Author: markt
Date: Tue Sep 8 12:54:43 2015
New Revision: 1701796
URL: http://svn.apache.org/r1701796
Log:
More preparation for implementing parallel class loading.
Use an explicit synchronized block in loadClass
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java?rev=1701796&r1=1701795&r2=1701796&view=diff
==============================================================================
---
tomcat/tc7.0.x/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java
(original)
+++
tomcat/tc7.0.x/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java
Tue Sep 8 12:54:43 2015
@@ -1711,81 +1711,47 @@ public abstract class WebappClassLoaderB
* @exception ClassNotFoundException if the class was not found
*/
@Override
- public synchronized Class<?> loadClass(String name, boolean resolve)
- throws ClassNotFoundException {
+ 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 (this) {
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 = j2seClassLoader.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);
+
+ // (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, parent);
+ clazz = j2seClassLoader.loadClass(name);
if (clazz != null) {
- if (log.isDebugEnabled())
- log.debug(" Loading class from parent");
if (resolve)
resolveClass(clazz);
return (clazz);
@@ -1793,33 +1759,50 @@ public abstract class WebappClassLoaderB
} 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);
+ try {
+ clazz = Class.forName(name, false, parent);
+ 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);
+ log.debug(" Searching local repositories");
try {
- clazz = Class.forName(name, false, parent);
+ 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);
@@ -1827,10 +1810,27 @@ public abstract class WebappClassLoaderB
} catch (ClassNotFoundException e) {
// Ignore
}
+
+ // (3) Delegate to parent unconditionally
+ if (!delegateLoad) {
+ if (log.isDebugEnabled())
+ log.debug(" Delegating to parent classloader at end: " +
parent);
+ try {
+ clazz = Class.forName(name, false, parent);
+ 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);
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]