Bug 464442 - Enable parallel class loading

Change-Id: If23cc99214efe8d3a75d0ab0d337020524b6709f
Signed-off-by: Philippe Marschall <philippe.marschall@netcetera.ch>
This commit is contained in:
Philippe Marschall 2015-04-11 15:03:01 +02:00 committed by Greg Wilkins
parent eee2a53197
commit fb58ca79c0
2 changed files with 62 additions and 49 deletions

View File

@ -36,6 +36,11 @@ public class Classpath implements Iterable<File>
{
private static class Loader extends URLClassLoader
{
static
{
registerAsParallelCapable();
}
Loader(URL[] urls, ClassLoader parent)
{
super(urls,parent);

View File

@ -65,6 +65,11 @@ import org.eclipse.jetty.util.resource.ResourceCollection;
*/
public class WebAppClassLoader extends URLClassLoader
{
static
{
registerAsParallelCapable();
}
private static final Logger LOG = Log.getLogger(WebAppClassLoader.class);
private final Context _context;
@ -404,60 +409,63 @@ public class WebAppClassLoader extends URLClassLoader
/* ------------------------------------------------------------ */
@Override
protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
{
Class<?> c= findLoadedClass(name);
ClassNotFoundException ex= null;
boolean tried_parent= false;
boolean system_class=_context.isSystemClass(name);
boolean server_class=_context.isServerClass(name);
if (system_class && server_class)
synchronized (getClassLoadingLock(name))
{
return null;
}
if (c == null && _parent!=null && (_context.isParentLoaderPriority() || system_class) && !server_class)
{
tried_parent= true;
try
Class<?> c= findLoadedClass(name);
ClassNotFoundException ex= null;
boolean tried_parent= false;
boolean system_class=_context.isSystemClass(name);
boolean server_class=_context.isServerClass(name);
if (system_class && server_class)
{
return null;
}
if (c == null && _parent!=null && (_context.isParentLoaderPriority() || system_class) && !server_class)
{
tried_parent= true;
try
{
c= _parent.loadClass(name);
if (LOG.isDebugEnabled())
LOG.debug("loaded " + c);
}
catch (ClassNotFoundException e)
{
ex= e;
}
}
if (c == null)
{
try
{
c= this.findClass(name);
}
catch (ClassNotFoundException e)
{
ex= e;
}
}
if (c == null && _parent!=null && !tried_parent && !server_class )
c= _parent.loadClass(name);
if (LOG.isDebugEnabled())
LOG.debug("loaded " + c);
}
catch (ClassNotFoundException e)
{
ex= e;
}
if (c == null && ex!=null)
throw ex;
if (resolve)
resolveClass(c);
if (LOG.isDebugEnabled())
LOG.debug("loaded {} from {}",c,c==null?null:c.getClassLoader());
return c;
}
if (c == null)
{
try
{
c= this.findClass(name);
}
catch (ClassNotFoundException e)
{
ex= e;
}
}
if (c == null && _parent!=null && !tried_parent && !server_class )
c= _parent.loadClass(name);
if (c == null && ex!=null)
throw ex;
if (resolve)
resolveClass(c);
if (LOG.isDebugEnabled())
LOG.debug("loaded {} from {}",c,c==null?null:c.getClassLoader());
return c;
}
/* ------------------------------------------------------------ */