com.atlassian.plugin.util
Class ContextClassLoaderSwitchingUtil

java.lang.Object
  extended by com.atlassian.plugin.util.ContextClassLoaderSwitchingUtil

public class ContextClassLoaderSwitchingUtil
extends Object

Utility to run Runnable implementations in a different ClassLoader.

Since:
2.5.0

Constructor Summary
ContextClassLoaderSwitchingUtil()
           
 
Method Summary
static
<T> T
runInContext(ClassLoader newClassLoader, Callable<T> callable)
          Executes the provided Callable implementation in the specified ClassLoader.
static void runInContext(ClassLoader newClassLoader, Runnable runnable)
          Executes the provided Runnable implementation in the specified ClassLoader.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContextClassLoaderSwitchingUtil

public ContextClassLoaderSwitchingUtil()
Method Detail

runInContext

public static void runInContext(ClassLoader newClassLoader,
                                Runnable runnable)
Executes the provided Runnable implementation in the specified ClassLoader.

Utilises the ClassLoaderStack.push(java.lang.ClassLoader) method to save the old ClassLoader and set the one specified as newClassLoader. ClassLoaderStack.pop() is called in a finally block to ensure the ClassLoader is set back to the original one.

Parameters:
newClassLoader - The ClassLoader to run the specified Runnable in.
runnable - The implementation to be run in the specified ClassLoader

runInContext

public static <T> T runInContext(ClassLoader newClassLoader,
                                 Callable<T> callable)
                      throws Exception
Executes the provided Callable implementation in the specified ClassLoader.

Utilises the ClassLoaderStack.push(java.lang.ClassLoader) method to save the old ClassLoader and set the one specified as newClassLoader. ClassLoaderStack.pop() is called in a finally block to ensure the ClassLoader is set back to the original one.

Parameters:
newClassLoader - The ClassLoader to run the specified Runnable in.
callable - The implementation to be run in the specified ClassLoader
Returns:
the result of the Callable
Throws:
Exception
Since:
2.7.0


Copyright © 2014 Atlassian. All rights reserved.