ResourceManager启动和关闭时日志打印

启动日志打印:入口

主要打印:见红色字体处,也就是日志当中的信息

StringUtils.startupShutdownMessage(ResourceManager.class, argv, LOG);

 

/**
* Print a log message for starting up and shutting down
* @param clazz the class of the server
* @param args arguments
* @param LOG the target log object
*/
public static void startupShutdownMessage(Class<?> clazz, String[] args,
                                   final org.apache.commons.logging.Log LOG) {
  startupShutdownMessage(clazz, args, LogAdapter.create(LOG));
}

 

static void startupShutdownMessage(Class<?> clazz, String[] args,
                                   final LogAdapter LOG) {
  final String hostname = NetUtils.getHostname();  // 获取本地主机名
  final String classname = clazz.getSimpleName();  // 获取类名
  LOG.info(
     toStartupShutdownString("STARTUP_MSG: ", new String[] {  // 仅仅格式化代码
          "Starting " + classname,
          "  host = " + hostname,
          "  args = " + Arrays.asList(args),
          "  version = " + VersionInfo.getVersion(),
          "  classpath = " + System.getProperty("java.class.path"),
          "  build = " + VersionInfo.getUrl() + " -r "
                       + VersionInfo.getRevision() 
                       + "; compiled by '" + VersionInfo.getUser()
                       + "' on " + VersionInfo.getDate(),
          "  java = " + System.getProperty("java.version") }
      )
    );

  if (SystemUtils.IS_OS_UNIX) {
    try {
     SignalLogger.INSTANCE.register(LOG);  //如果为linux,注册一些信号操作
    } catch (Throwable t) {
      LOG.warn("failed to register any UNIX signal loggers: ", t);
    }
  }
  ShutdownHookManager.get().addShutdownHook( //注册钩子,这应该是RM第一个钩子
    new Runnable() {
      @Override
      public void run() {
        LOG.info(toStartupShutdownString("SHUTDOWN_MSG: ", new String[]{
          "Shutting down " + classname + " at " + hostname}));
      }
    }, SHUTDOWN_HOOK_PRIORITY);

}

 

下面单独来看看来,HookManager是怎么来实现,顺序执行并有调度优先级的。JVM默认顺序未指定,还是并行来执行的

ShutdownHookManager

转载于:https://www.cnblogs.com/yanbit/p/4739568.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值