com.atlassian.plugin.util
Class ClassLoaderStack
java.lang.Object
com.atlassian.plugin.util.ClassLoaderStack
public class ClassLoaderStack
- extends java.lang.Object
This utility provides a thread local stack of ClassLoaders.
The current "top" of the stack is the thread's current context class loader.
This can be used when implementing delegating plugin java.util.logging.Filters or Servlets
that need to set the ClassLoader to the PluginClassLoader the filter
or servlet is declared in.
- Since:
- 2.5.0
|
Method Summary |
static java.lang.ClassLoader |
pop()
Pops the current ContextClassLoader off the stack, setting the new ContextClassLoader to the previous one on the stack. |
static void |
push(java.lang.ClassLoader loader)
Makes the given classLoader the new ContextClassLoader for this thread, and pushes the current ContextClassLoader
onto a ThreadLocal stack so that we can do a pop() operation later to return to that ContextClassLoader. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ClassLoaderStack
public ClassLoaderStack()
push
public static void push(java.lang.ClassLoader loader)
- Makes the given classLoader the new ContextClassLoader for this thread, and pushes the current ContextClassLoader
onto a ThreadLocal stack so that we can do a
pop() operation later to return to that ContextClassLoader.
Passing null is allowed and will act as a no-op. This means that you can safely pop() a ClassLoader and push(java.lang.ClassLoader) it back in
and it will work safely whether the stack was empty at time of pop() or not.
- Parameters:
loader - The new ClassLoader to set as ContextClassLoader.
pop
public static java.lang.ClassLoader pop()
- Pops the current ContextClassLoader off the stack, setting the new ContextClassLoader to the previous one on the stack.
- If the stack is not empty, then the current ClassLoader is replaced by the previous one on the stack, and then returned.
- If the stack is empty, then null is returned and the current ContextClassLoader is not changed.
- Returns:
- the previous ContextClassLoader that was just replaced, or null if the stack is empty.
Copyright © 2012 Atlassian. All Rights Reserved.