启动日志打印:入口
主要打印:见红色字体处,也就是日志当中的信息
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