Commit ba5e6b24 by rmani

ATLAS-3092:Atlas Plugin ClassLoader Doesn't Restore Thread ClassLoader

parent 727e6e03
...@@ -39,6 +39,8 @@ public final class AtlasPluginClassLoader extends URLClassLoader { ...@@ -39,6 +39,8 @@ public final class AtlasPluginClassLoader extends URLClassLoader {
private static volatile AtlasPluginClassLoader me = null; private static volatile AtlasPluginClassLoader me = null;
private final ThreadLocal<ClassLoader> preActivateClassLoader = new ThreadLocal<>();
private final MyClassLoader componentClassLoader; private final MyClassLoader componentClassLoader;
private AtlasPluginClassLoader(String pluginType, Class<?> pluginClass) throws URISyntaxException { private AtlasPluginClassLoader(String pluginType, Class<?> pluginClass) throws URISyntaxException {
...@@ -207,6 +209,8 @@ public final class AtlasPluginClassLoader extends URLClassLoader { ...@@ -207,6 +209,8 @@ public final class AtlasPluginClassLoader extends URLClassLoader {
LOG.debug("==> AtlasPluginClassLoader.activate()"); LOG.debug("==> AtlasPluginClassLoader.activate()");
} }
preActivateClassLoader.set(Thread.currentThread().getContextClassLoader());
Thread.currentThread().setContextClassLoader(this); Thread.currentThread().setContextClassLoader(this);
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
...@@ -219,10 +223,19 @@ public final class AtlasPluginClassLoader extends URLClassLoader { ...@@ -219,10 +223,19 @@ public final class AtlasPluginClassLoader extends URLClassLoader {
LOG.debug("==> AtlasPluginClassLoader.deactivate()"); LOG.debug("==> AtlasPluginClassLoader.deactivate()");
} }
MyClassLoader savedClassLoader = getComponentClassLoader(); ClassLoader classLoader = preActivateClassLoader.get();
if (classLoader != null) {
preActivateClassLoader.remove();
} else {
MyClassLoader savedClassLoader = getComponentClassLoader();
if (savedClassLoader != null && savedClassLoader.getParent() != null) { if (savedClassLoader != null && savedClassLoader.getParent() != null) {
Thread.currentThread().setContextClassLoader(savedClassLoader.getParent()); classLoader = savedClassLoader.getParent();
}
}
if (classLoader != null) {
Thread.currentThread().setContextClassLoader(classLoader);
} else { } else {
LOG.warn("AtlasPluginClassLoader.deactivate() was not successful.Couldn't not get the saved " LOG.warn("AtlasPluginClassLoader.deactivate() was not successful.Couldn't not get the saved "
+ "componentClassLoader..."); + "componentClassLoader...");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment