提交 75ada9fe 编写于 作者: wu-sheng's avatar wu-sheng

Add jvm shutdown hook

上级 6c5636f2
......@@ -13,4 +13,6 @@ public interface BootService {
void boot() throws Throwable;
void afterBoot() throws Throwable;
void shutdown() throws Throwable;
}
......@@ -27,6 +27,16 @@ public enum ServiceManager {
afterBoot();
}
public void shutdown() {
for (BootService service : bootedServices.values()) {
try {
service.shutdown();
} catch (Throwable e) {
logger.error(e, "ServiceManager try to shutdown [{}] fail.", service.getClass().getName());
}
}
}
private Map<Class, BootService> loadAllServices() {
HashMap<Class, BootService> bootedServices = new HashMap<Class, BootService>();
Iterator<BootService> serviceIterator = load().iterator();
......
......@@ -162,6 +162,10 @@ public class ContextManager implements TracingContextListener, BootService, Igno
}
@Override public void shutdown() throws Throwable {
}
@Override
public void afterFinished(TraceSegment traceSegment) {
CONTEXT.remove();
......
......@@ -44,6 +44,12 @@ public class SkyWalkingAgent {
ServiceManager.INSTANCE.boot();
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override public void run() {
ServiceManager.INSTANCE.shutdown();
}
}, "skywalking service shutdown thread"));
new AgentBuilder.Default().type(pluginFinder.buildMatch()).transform(new AgentBuilder.Transformer() {
@Override
public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDescription typeDescription,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册