Skip to content

Commit

Permalink
Fix ready thread classloader
Browse files Browse the repository at this point in the history
  • Loading branch information
hexiaofeng committed Jun 7, 2024
1 parent fc92feb commit 3254c83
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public interface AgentLifecycle {
* that should occur once the system has completed its startup process.
*
* @param callable the hook to be executed when the system is ready
* @param classLoader execute in this classloader
*/
void addReadyHook(Callable<?> callable);
void addReadyHook(Callable<?> callable, ClassLoader classLoader);
}
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,17 @@ public void execute(String command, Map<String, Object> args) {
}

@Override
public void addReadyHook(Callable<?> callable) {
public void addReadyHook(Callable<?> callable, ClassLoader classLoader) {
if (callable != null) {
readies.add(callable);
readies.add(() -> {
ClassLoader old = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(classLoader);
try {
return callable.call();
} finally {
Thread.currentThread().setContextClassLoader(old);
}
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void onEnter(ExecutableContext ctx) {
logger.info("Register when application is ready, service=" + instance.getService());
registry.register(instance);
return mc.invoke();
});
}, ctx.getType().getClassLoader());
mc.setSkip(true);
}
}
Expand Down

0 comments on commit 3254c83

Please sign in to comment.