public class ContextClassLoaderSwitcher extends ContextClassLoader
When a security manager is installed, the constructor checks for the runtime permissions "getClassLoader" and "setContextClassLoader". This allows the methods of this class to be used later without having to run in privileged blocks. There are optimized methods to perform the operations within a switch context. This avoids retrieving the current thread on every operation.
Modifier and Type | Class and Description |
---|---|
class |
ContextClassLoaderSwitcher.SwitchContext
A helper class to remember the original classloader and
avoid continually retrieveing the current thread.
|
Modifier and Type | Field and Description |
---|---|
static org.jboss.util.loading.ContextClassLoaderSwitcher.NewInstance |
INSTANTIATOR
Instantiate a new context class loader switcher
|
static RuntimePermission |
SETCONTEXTCLASSLOADER
Set the context classloader permission
|
GETCLASSLOADER
Modifier and Type | Method and Description |
---|---|
ContextClassLoaderSwitcher.SwitchContext |
getSwitchContext()
Retrieve a switch context
|
ContextClassLoaderSwitcher.SwitchContext |
getSwitchContext(Class clazz)
Deprecated.
using a class to determine the classloader is a
bad idea, it has the same problems as Class.forName()
|
ContextClassLoaderSwitcher.SwitchContext |
getSwitchContext(ClassLoader cl)
Retrieve a switch context and set the new context classloader
|
void |
setContextClassLoader(ClassLoader cl)
Set the context classloader
|
void |
setContextClassLoader(Thread thread,
ClassLoader cl)
Set the context classloader for the given thread
|
getContextClassLoader, getContextClassLoader
public static final RuntimePermission SETCONTEXTCLASSLOADER
public static final org.jboss.util.loading.ContextClassLoaderSwitcher.NewInstance INSTANTIATOR
public void setContextClassLoader(ClassLoader cl)
cl
- public void setContextClassLoader(Thread thread, ClassLoader cl)
thread
- the threadcl
- the new context classloaderpublic ContextClassLoaderSwitcher.SwitchContext getSwitchContext()
public ContextClassLoaderSwitcher.SwitchContext getSwitchContext(ClassLoader cl)
cl
- the new classloaderpublic ContextClassLoaderSwitcher.SwitchContext getSwitchContext(Class clazz)
clazz
- the class whose classloader should be set
as the context classloaderCopyright © 2018 JBoss by Red Hat. All rights reserved.