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 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


Copyright © 2011 Atlassian. All Rights Reserved.