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

ResourceManager中setDefaultUncaughtExceptionHandler做了那些事情

时间:2015-08-18 13:43:59      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

public static void main(String argv[]) {
  Thread.setDefaultUncaughtExceptionHandler(new YarnUncaughtExceptionHandler());
  StringUtils.startupShutdownMessage(ResourceManager.class, argv, LOG);
… 

}

YarnUncaughtExceptionHandler类主要结构,其实就是记录LOG

public class YarnUncaughtExceptionHandler implements UncaughtExceptionHandler {
  private static final Log LOG = LogFactory.getLog(YarnUncaughtExceptionHandler.class);
 
  @Override
  public void uncaughtException(Thread t, Throwable e) {
    if(ShutdownHookManager.get().isShutdownInProgress()) {
      LOG.error("Thread " + t + " threw an Throwable, but we are shutting " +
              "down, so ignoring this", e);
    } else if(e instanceof Error) {
      try {
        LOG.fatal("Thread " + t + " threw an Error.  Shutting down now...", e);
      } catch (Throwable err) {
        //We don‘t want to not exit because of an issue with logging
      }
      if(e instanceof OutOfMemoryError) {
        //After catching an OOM java says it is undefined behavior, so don‘t
        //even try to clean up or we can get stuck on shutdown.
        try {
          System.err.println("Halting due to Out Of Memory Error...");
        } catch (Throwable err) {
          //Again we done want to exit because of logging issues.
        }
        ExitUtil.halt(-1);
      } else {
        ExitUtil.terminate(-1);
      }
    } else {
      LOG.error("Thread " + t + " threw an Exception.", e);
    }
  }
}

ResourceManager中setDefaultUncaughtExceptionHandler做了那些事情

标签:

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

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