@Override
    public void registerStopHandler() {
        if (applicationContext instanceof DefaultApplicationContext) {
            logger.info("registerStopHandler");

            DefaultApplicationContext context = (DefaultApplicationContext) applicationContext;
            ShutdownHookRegisterProvider shutdownHookRegisterProvider = context.getShutdownHookRegisterProvider();
            ShutdownHookRegister shutdownHookRegister = shutdownHookRegisterProvider.get();

            PinpointThreadFactory pinpointThreadFactory = new PinpointThreadFactory("Pinpoint-shutdown-hook", false);
            Thread shutdownThread = pinpointThreadFactory.newThread(new Runnable() {
                @Override
                public void run() {
                    logger.info("stop() started. threadName:" + Thread.currentThread().getName());
                    DefaultAgent.this.close();
                }
            });

            shutdownHookRegister.register(shutdownThread);

        }

    }
@author emeroad
@author koo.taejin
@author hyungil.jeong
agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/DefaultAgent.java