Skip to content

Commit

Permalink
修复shutdown命令无法正确执行的BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
杜琨 committed Mar 11, 2018
1 parent dd5d771 commit 7ea27c5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@ private static synchronized ClassLoader loadOrDefineClassLoader(final String nam
return classLoader;
}

/**
* 获取当前命名空间下的ClassLoader
*
* @param namespace 命名空间
* @return 当前的ClassLoader
* @since {@code sandbox-api:1.0.15}
*/
public static ClassLoader getClassLoader(final String namespace) {
return sandboxClassLoaderMap.get(namespace);
}

/**
* 清理namespace所指定的ClassLoader
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ public class ControlModule implements Module {
@Resource
private ModuleManager moduleManager;

private ClassLoader getSandboxClassLoader(final Class<?> classOfAgentLauncher)
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
final ClassLoader sandboxClassLoader = (ClassLoader) MethodUtils.invokeStaticMethod(
classOfAgentLauncher,
"getClassLoader",
configInfo.getNamespace()
);
return sandboxClassLoader;
}

// 清理命名空间所对应的SandboxClassLoader
private ClassLoader cleanSandboxClassLoader(final Class<?> classOfAgentLauncher)
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
Expand Down Expand Up @@ -116,8 +126,6 @@ public void shutdown(final HttpServletResponse resp) throws Exception {
final Class<?> classOfAgentLauncher = getClass().getClassLoader()
.loadClass("com.alibaba.jvm.sandbox.agent.AgentLauncher");

// 清理引用
final ClassLoader sandboxClassLoader = cleanSandboxClassLoader(classOfAgentLauncher);
cleanSpy();

// 卸载模块
Expand All @@ -128,9 +136,14 @@ public void shutdown(final HttpServletResponse resp) throws Exception {
@Override
public void run() {
try {
unloadSelf();
shutdownServer(sandboxClassLoader);

shutdownServer(getSandboxClassLoader(classOfAgentLauncher));
logger.info("shutdown jvm-sandbox finished.");

// 清理引用
unloadSelf();
cleanSandboxClassLoader(classOfAgentLauncher);

} catch (Throwable cause) {
logger.warn("shutdown jvm-sandbox failed.", cause);
}
Expand Down

0 comments on commit 7ea27c5

Please sign in to comment.