Top Description Fields Constructors Methods
org.jboss.modules

public abstract Class ConcurrentClassLoader

extends NamedClassLoader
Class Inheritance
Known Direct Subclasses
org.jboss.modules.ModuleClassLoader
Imports
java.io.IOException, .InputStream, java.net.URL, java.security.ProtectionDomain, java.util.ArrayList, .Arrays, .Collections, .Enumeration, java.util.concurrent.ConcurrentHashMap

A classloader which can delegate to multiple other classloaders without risk of deadlock. A concurrent class loader should only ever be delegated to by another concurrent class loader; however a concurrent class loader may delegate to a standard hierarchical class loader. In other words, holding a lock on another class loader while invoking a method on this class loader may cause an unexpected deadlock.
Author
David M. Lloyd

Field Summary

Modifier and TypeField and Description
protected static final Enumeration<URL>
EMPTY_ENUMERATION

An empty enumeration, for subclasses to use if desired.

private static final ThreadLocal<Boolean>
private final ConcurrentHashMap<String, Package>

Constructor Summary

AccessConstructor and Description
protected
ConcurrentClassLoader(final ConcurrentClassLoader
the parent class loader
parent
)

Construct a new instance with the given parent class loader, which must be a concurrent class loader, or null to create a root concurrent class loader.

protected
ConcurrentClassLoader()

Construct a new instance, using our class loader as the parent.

protected
ConcurrentClassLoader(final ConcurrentClassLoader
the parent class loader
parent
,
final String
the name of this class loader, or null if it is unnamed
name
)

Construct a new instance with the given parent class loader, which must be a concurrent class loader, or null to create a root concurrent class loader.

protected
ConcurrentClassLoader(String
the name of this class loader, or null if it is unnamed
name
)

Construct a new instance, using our class loader as the parent.

Method Summary

Modifier and TypeMethod and Description
protected final Class<?>

Returns:

the class
defineOrLoadClass
(final String
the class name to define or load
className
,
final byte[]
the bytes to use to define the class
bytes
,
int
the offset into the byte array at which the class bytes begin
off
,
int
the number of bytes in the class
len
)

Atomically define or load the named class.

protected final Class<?>

Returns:

the class
defineOrLoadClass
(final String
the class name to define or load
className
,
final byte[]
the bytes to use to define the class
bytes
,
int
the offset into the byte array at which the class bytes begin
off
,
int
the number of bytes in the class
len
,
ProtectionDomain
the protection domain for the defined class
protectionDomain
)

Atomically define or load the named class.

protected Package

Returns:

the newly defined package, or the existing one if one was already defined
definePackage
(final String
the package name
name
,
final String
the specification title
specTitle
,
final String
the specification version
specVersion
,
final String
the specification vendor
specVendor
,
final String
the implementation title
implTitle
,
final String
the implementation version
implVersion
,
final String
the implementation vendor
implVendor
,
final URL
if not null, then this package is sealed with respect to the given code source URL
sealBase
)

Overrides java.lang.ClassLoader.definePackage.

Defines a package by name in this ConcurrentClassLoader.
protected Class<?>

Returns:

the class
findClass
(final String
the class name
className
,
final boolean
true if only exported classes should be considered
exportsOnly
,
final boolean
true if the class should be linked after loading
resolve
)

Find a class, possibly delegating to other loader(s).

protected final Class<?>

Returns:

the result of findClass(className, false, false)
findClass
(final String
the class name
className
)

Overrides java.lang.ClassLoader.findClass.

Implementation of ClassLoader#findClass(String).
protected final Class<?>

Returns:

the result of findClass(className, false, false)
findClass
(final String
the Java module name
moduleName
,
final String
the class name
className
)

Overrides java.lang.ClassLoader.findClass.

Implementation of ClassLoader#findClass(String, String).
protected final Package

Returns:

the package or null if no such package is defined by this class loader
findLoadedPackage
(final String
the package name
name
)

Load a package from this class loader only.

protected URL

Returns:

the resource URL
findResource
(final String
the resource name
name
,
final boolean
true to consider only exported resources or false to consider all resources
exportsOnly
)

Find the resource with the given name and exported status.

protected final URL

Returns:

null always
findResource
(final String
ignored
name
)

Overrides java.lang.ClassLoader.findResource.

Never used.
protected final URL

Returns:

the resource URL
findResource
(final String
java module name
moduleName
,
final String
the resource name
name
)

Overrides java.lang.ClassLoader.findResource.

Find the resource with the given name in specified java module.
protected InputStream

Returns:

the resource stream, or null if the resource is not found
findResourceAsStream
(final String
the resource name
name
,
final boolean
true to consider only exported resources or false to consider all resources
exportsOnly
)

Finds the resource with the given name and exported status, returning the resource content as a stream.

protected Enumeration<URL>

Returns:

the resource enumeration
findResources
(final String
the resource name
name
,
final boolean
true to consider only exported resources or false to consider all resources
exportsOnly
)

Finds the resources with the given name and exported status.

protected final Enumeration<URL>

Returns:

an empty enumeration
findResources
(final String
ignored
name
)

Overrides java.lang.ClassLoader.findResources.

Never used.
pack-priv Class<?>
pack-priv static Object
protected final Package

Returns:

the package, or null if no such package is visible to this class loader
getPackage
(final String
the package name
name
)

Overrides java.lang.ClassLoader.getPackage.

Load a package which is visible to this class loader.
protected Package

Returns:

the package, or null if no such package is visible to this class loader
getPackageByName
(final String
the package name
name
)

Perform the actual work to load a package which is visible to this class loader.

protected Package[]

Returns:

the packages
getPackages
()

Overrides java.lang.ClassLoader.getPackages.

Get all defined packages which are visible to this class loader.
public final URL

Returns:

the resource URL, or null if no such resource exists or the invoker does not have adequate permission to access it
getResource
(final String
the name of the resource
name
)

Overrides java.lang.ClassLoader.getResource.

Finds the resource with the given name.
public final InputStream

Returns:

the resource stream, or null if the resource is not found
getResourceAsStream
(final String
the resource name
name
)

Overrides java.lang.ClassLoader.getResourceAsStream.

Returns an input stream for reading the specified resource.
public final Enumeration<URL>

Returns:

an enumeration over all the resource URLs; if no resources could be found, the enumeration will be empty
getResources
(final String
the resource name
name
)

Overrides java.lang.ClassLoader.getResources.

Finds all available resources with the given name.
public final Class<?>

Returns:

the resulting Class instance
loadClass
(final String
The binary name of the class
className
)

Overrides java.lang.ClassLoader.loadClass.

Loads the class with the specified binary name.
public final Class<?>

Returns:

the resulting Class instance
loadClass
(final String
The binary name of the class
className
,
boolean
true if the class should be linked after loading
resolve
)

Overrides java.lang.ClassLoader.loadClass.

Loads the class with the specified binary name.
public final Class<?>

Returns:

the class
loadExportedClass
(final String
the class name
className
)

Same as loadClass(String), except only exported classes will be considered.

public final Class<?>

Returns:

the class
loadExportedClass
(final String
the class name
className
,
boolean
true if the class should be linked after loading
resolve
)

Same as loadClass(String, boolean), except only exported classes will be considered.

private Class<?>

Returns:

the class returned by findClass(String, boolean, boolean)
performLoadClass
(String
the class name
className
,
boolean
true to consider only exported resources or false to consider all resources
exportsOnly
,
final boolean
true to resolve the loaded class
resolve
)

Perform a class load operation.

private Class<?>
performLoadClassUnchecked(final String className, final boolean exportsOnly, final boolean resolve)

Inherited from org.jboss.modules.NamedClassLoader:
getName

Field Detail

EMPTY_ENUMERATIONback to summary
protected static final Enumeration<URL> EMPTY_ENUMERATION

An empty enumeration, for subclasses to use if desired.

GET_PACKAGE_SUPPRESSORback to summary
private static final ThreadLocal<Boolean> GET_PACKAGE_SUPPRESSOR
packagesback to summary
private final ConcurrentHashMap<String, Package> packages

Hides java.lang.ClassLoader.packages.

Constructor Detail

ConcurrentClassLoaderback to summary
protected ConcurrentClassLoader(final ConcurrentClassLoader parent)

Construct a new instance with the given parent class loader, which must be a concurrent class loader, or null to create a root concurrent class loader.

Parameters
parent:ConcurrentClassLoader

the parent class loader

ConcurrentClassLoaderback to summary
protected ConcurrentClassLoader()

Construct a new instance, using our class loader as the parent.

ConcurrentClassLoaderback to summary
protected ConcurrentClassLoader(final ConcurrentClassLoader parent, final String name)

Construct a new instance with the given parent class loader, which must be a concurrent class loader, or null to create a root concurrent class loader.

Parameters
parent:ConcurrentClassLoader

the parent class loader

name:String

the name of this class loader, or null if it is unnamed

ConcurrentClassLoaderback to summary
protected ConcurrentClassLoader(String name)

Construct a new instance, using our class loader as the parent.

Parameters
name:String

the name of this class loader, or null if it is unnamed

Method Detail

defineOrLoadClassback to summary
protected final Class<?> defineOrLoadClass(final String className, final byte[] bytes, int off, int len)

Atomically define or load the named class. If the class is already defined, the existing class is returned.

Parameters
className:String

the class name to define or load

bytes:byte[]

the bytes to use to define the class

off:int

the offset into the byte array at which the class bytes begin

len:int

the number of bytes in the class

Returns:Class<?>

the class

defineOrLoadClassback to summary
protected final Class<?> defineOrLoadClass(final String className, final byte[] bytes, int off, int len, ProtectionDomain protectionDomain)

Atomically define or load the named class. If the class is already defined, the existing class is returned.

Parameters
className:String

the class name to define or load

bytes:byte[]

the bytes to use to define the class

off:int

the offset into the byte array at which the class bytes begin

len:int

the number of bytes in the class

protectionDomain:ProtectionDomain

the protection domain for the defined class

Returns:Class<?>

the class

definePackageback to summary
protected Package definePackage(final String name, final String specTitle, final String specVersion, final String specVendor, final String implTitle, final String implVersion, final String implVendor, final URL sealBase) throws IllegalArgumentException

Overrides java.lang.ClassLoader.definePackage.

Defines a package by name in this ConcurrentClassLoader. If the package was already defined, the existing package is returned instead.

Parameters
name:String

the package name

specTitle:String

the specification title

specVersion:String

the specification version

specVendor:String

the specification vendor

implTitle:String

the implementation title

implVersion:String

the implementation version

implVendor:String

the implementation vendor

sealBase:URL

if not null, then this package is sealed with respect to the given code source URL

Returns:Package

the newly defined package, or the existing one if one was already defined

Exceptions
IllegalArgumentException:

Doc from java.lang.ClassLoader.definePackage.

if a package of the given name is already defined by this class loader

findClassback to summary
protected Class<?> findClass(final String className, final boolean exportsOnly, final boolean resolve) throws ClassNotFoundException

Find a class, possibly delegating to other loader(s). This method should never synchronize across a delegation method call of any sort. The default implementation always throws ClassNotFoundException.

If a class is to be defined by this method, it should be done via one of the atomic defineOrLoadClass methods rather than defineClass() in order to avoid spurious exceptions.

Parameters
className:String

the class name

exportsOnly:boolean

true if only exported classes should be considered

resolve:boolean

true if the class should be linked after loading

Returns:Class<?>

the class

Exceptions
ClassNotFoundException:
if the class is not found
findClassback to summary
protected final Class<?> findClass(final String className) throws ClassNotFoundException

Overrides java.lang.ClassLoader.findClass.

Implementation of ClassLoader#findClass(String).

Parameters
className:String

the class name

Returns:Class<?>

the result of findClass(className, false, false)

Exceptions
ClassNotFoundException:

Doc from java.lang.ClassLoader.findClass.

If the class could not be found

findClassback to summary
protected final Class<?> findClass(final String moduleName, final String className)

Overrides java.lang.ClassLoader.findClass.

Implementation of ClassLoader#findClass(String, String).

Parameters
moduleName:String

the Java module name

className:String

the class name

Returns:Class<?>

the result of findClass(className, false, false)

findLoadedPackageback to summary
protected final Package findLoadedPackage(final String name)

Load a package from this class loader only.

Parameters
name:String

the package name

Returns:Package

the package or null if no such package is defined by this class loader

findResourceback to summary
protected URL findResource(final String name, final boolean exportsOnly)

Find the resource with the given name and exported status.

Parameters
name:String

the resource name

exportsOnly:boolean

true to consider only exported resources or false to consider all resources

Returns:URL

the resource URL

See Also
getResource(String)
findResourceback to summary
protected final URL findResource(final String name)

Overrides java.lang.ClassLoader.findResource.

Never used. ClassLoader#getResource(String) and related methods can cause a loop condition when this method is implemented; use findResource(String, boolean) instead.

Parameters
name:String

ignored

Returns:URL

null always

findResourceback to summary
protected final URL findResource(final String moduleName, final String name) throws IOException

Overrides java.lang.ClassLoader.findResource.

Find the resource with the given name in specified java module.

Parameters
moduleName:String

java module name

name:String

the resource name

Returns:URL

the resource URL

Exceptions
IOException:

Doc from java.lang.ClassLoader.findResource.

If I/O errors occur

See Also
getResource(String)
findResourceAsStreamback to summary
protected InputStream findResourceAsStream(final String name, final boolean exportsOnly)

Finds the resource with the given name and exported status, returning the resource content as a stream.

Parameters
name:String

the resource name

exportsOnly:boolean

true to consider only exported resources or false to consider all resources

Returns:InputStream

the resource stream, or null if the resource is not found

findResourcesback to summary
protected Enumeration<URL> findResources(final String name, final boolean exportsOnly) throws IOException

Finds the resources with the given name and exported status.

Parameters
name:String

the resource name

exportsOnly:boolean

true to consider only exported resources or false to consider all resources

Returns:Enumeration<URL>

the resource enumeration

Exceptions
IOException:
if an I/O error occurs
See Also
getResources(String)
findResourcesback to summary
protected final Enumeration<URL> findResources(final String name)

Overrides java.lang.ClassLoader.findResources.

Never used. ClassLoader#getResources(String) and related methods can cause a loop condition when this method is implemented; use findResources(String, boolean) instead. By default, returns an empty enumeration.

Parameters
name:String

ignored

Returns:Enumeration<URL>

an empty enumeration

findSystemClassInternalback to summary
pack-priv Class<?> findSystemClassInternal(String name) throws ClassNotFoundException
getLockForClassback to summary
pack-priv static Object getLockForClass(ConcurrentClassLoader cl, String name)
getPackageback to summary
protected final Package getPackage(final String name)

Overrides java.lang.ClassLoader.getPackage.

Load a package which is visible to this class loader.

Parameters
name:String

the package name

Returns:Package

the package, or null if no such package is visible to this class loader

getPackageByNameback to summary
protected Package getPackageByName(final String name)

Perform the actual work to load a package which is visible to this class loader. By default, uses a simple parent-first delegation strategy.

Parameters
name:String

the package name

Returns:Package

the package, or null if no such package is visible to this class loader

getPackagesback to summary
protected Package[] getPackages()

Overrides java.lang.ClassLoader.getPackages.

Get all defined packages which are visible to this class loader.

Returns:Package[]

the packages

getResourceback to summary
public final URL getResource(final String name)

Overrides java.lang.ClassLoader.getResource.

Finds the resource with the given name. The name of a resource is a '/'-separated path name that identifies the resource. If the resource name starts with "java/" then the parent class loader is used. Otherwise, this method delegates to findResource(String, boolean).

Parameters
name:String

the name of the resource

Returns:URL

the resource URL, or null if no such resource exists or the invoker does not have adequate permission to access it

getResourceAsStreamback to summary
public final InputStream getResourceAsStream(final String name)

Overrides java.lang.ClassLoader.getResourceAsStream.

Returns an input stream for reading the specified resource. This method delegates to findResourceAsStream(String, boolean).

Parameters
name:String

the resource name

Returns:InputStream

the resource stream, or null if the resource is not found

getResourcesback to summary
public final Enumeration<URL> getResources(final String name) throws IOException

Overrides java.lang.ClassLoader.getResources.

Finds all available resources with the given name.

Parameters
name:String

the resource name

Returns:Enumeration<URL>

an enumeration over all the resource URLs; if no resources could be found, the enumeration will be empty

Exceptions
IOException:
if an I/O error occurs
See Also
getResource(String)
loadClassback to summary
public final Class<?> loadClass(final String className) throws ClassNotFoundException

Overrides java.lang.ClassLoader.loadClass.

Loads the class with the specified binary name. Equivalent to calling loadClass(className, false).

Parameters
className:String

The binary name of the class

Returns:Class<?>

the resulting Class instance

Annotations
@Override
Exceptions
ClassNotFoundException:
if the class was not found
loadClassback to summary
public final Class<?> loadClass(final String className, boolean resolve) throws ClassNotFoundException

Overrides java.lang.ClassLoader.loadClass.

Loads the class with the specified binary name.

Parameters
className:String

The binary name of the class

resolve:boolean

true if the class should be linked after loading

Returns:Class<?>

the resulting Class instance

Annotations
@Override
Exceptions
ClassNotFoundException:

Doc from java.lang.ClassLoader.loadClass.

If the class could not be found

loadExportedClassback to summary
public final Class<?> loadExportedClass(final String className) throws ClassNotFoundException

Same as loadClass(String), except only exported classes will be considered.

Parameters
className:String

the class name

Returns:Class<?>

the class

Exceptions
ClassNotFoundException:
if the class isn't found
loadExportedClassback to summary
public final Class<?> loadExportedClass(final String className, boolean resolve) throws ClassNotFoundException

Same as loadClass(String, boolean), except only exported classes will be considered.

Parameters
className:String

the class name

resolve:boolean

true if the class should be linked after loading

Returns:Class<?>

the class

Exceptions
ClassNotFoundException:
if the class isn't found
performLoadClassback to summary
private Class<?> performLoadClass(String className, boolean exportsOnly, final boolean resolve) throws ClassNotFoundException

Perform a class load operation. If the class is in the package or a subpackage of a package in the system packages list, the parent class loader is used to load the class. Otherwise, this method checks to see if the class loader object is locked; if so, it unlocks it and submits the request to the class loader thread. Otherwise, it will load the class itself by delegating to findClass(String, boolean, boolean).

Parameters
className:String

the class name

exportsOnly:boolean

true to consider only exported resources or false to consider all resources

resolve:boolean

true to resolve the loaded class

Returns:Class<?>

the class returned by findClass(String, boolean, boolean)

Exceptions
ClassNotFoundException:
if findClass(String, boolean, boolean) throws this exception
performLoadClassUncheckedback to summary
private Class<?> performLoadClassUnchecked(final String className, final boolean exportsOnly, final boolean resolve) throws ClassNotFoundException