Add jvm shutdown hook
This commit is contained in:
parent
6c5636f221
commit
75ada9feaa
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue