Package com.atlassian.plugin.util
Class ContextClassLoaderSwitchingUtil
java.lang.Object
com.atlassian.plugin.util.ContextClassLoaderSwitchingUtil
Utility to run Runnable implementations in a different ClassLoader.
- Since:
- 2.5.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidrunInContext(ClassLoader newClassLoader, Runnable runnable) Executes the providedRunnableimplementation in the specifiedClassLoader.static <T> TrunInContext(ClassLoader newClassLoader, Callable<T> callable) Executes the providedCallableimplementation in the specifiedClassLoader.
-
Constructor Details
-
ContextClassLoaderSwitchingUtil
public ContextClassLoaderSwitchingUtil()
-
-
Method Details
-
runInContext
Executes the providedRunnableimplementation in the specifiedClassLoader.Utilises the
ClassLoaderStack.push(java.lang.ClassLoader)method to save the oldClassLoaderand set the one specified asnewClassLoader.ClassLoaderStack.pop()is called in a finally block to ensure theClassLoaderis set back to the original one.- Parameters:
newClassLoader- TheClassLoaderto run the specifiedRunnablein.runnable- The implementation to be run in the specifiedClassLoader
-
runInContext
Executes the providedCallableimplementation in the specifiedClassLoader.Utilises the
ClassLoaderStack.push(java.lang.ClassLoader)method to save the oldClassLoaderand set the one specified asnewClassLoader.ClassLoaderStack.pop()is called in a finally block to ensure theClassLoaderis set back to the original one.- Parameters:
newClassLoader- TheClassLoaderto run the specifiedRunnablein.callable- The implementation to be run in the specifiedClassLoader- Returns:
- the result of the
Callable - Throws:
Exception- Since:
- 2.7.0
-