码迷,mamicode.com
首页 > 其他好文 > 详细

ResourceManager启动和关闭时日志打印

时间:2015-08-18 18:30:41      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:

启动日志打印:入口

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

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

ResourceManager启动和关闭时日志打印

标签:

原文地址:http://www.cnblogs.com/yanbit/p/4739568.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!