Launcher类的构造函数
public Launcher() {
Launcher.ExtClassLoader var1;
try {
//1.先通过内部类获取ExtClassLoader
var1 = Launcher.ExtClassLoader.getExtClassLoader();
} catch (IOException var10) {
throw new InternalError("Could not create extension class loader");
}
try {
//2.再通过内部类获取AppClassLoader然后初始化classLoader对象
this.loader = Launcher.AppClassLoader.getAppClassLoader(var1);
} catch (IOException var9) {
throw new InternalError("Could not create application class loader");
}
//将当前线程的上下文类加载器设置为 AppClassLoader
Thread.currentThread().setContextClassLoader(this.loader);
String var2 = System.getProperty("java.security.manager");
//下面的代码就是通过AppClassLoader来加载安全管理器
if (var2 != null) {
SecurityManager var3 = null;
if (!"".equals(var2) && !"default".equals(var2)) {
try {
var3 = (SecurityManager)this.loader.loadClass(var2).newInstance();
} catch (IllegalAccessException var5) {
} catch (InstantiationException var6) {
} catch (ClassNotFoundException var7) {
} catch (ClassCastException var8) {
}
} else {
var3 = new SecurityManager();
}
if (var3 == null) {
throw new InternalError("Could not create SecurityManager: " var2);
}
//设置安全管理器,这里的安全管理器在需要加载类的时候要用到,需要对加载的类文件进行安全检查
System.setSecurityManager(var3);
}
}
参考:https://www.cnblogs.com/yiwangzhibujian/p/6207212.html
架构设计@工程设计@服务稳定性之路
来源:CSDN
作者:程序男
链接:https://blog.csdn.net/u010504064/article/details/103481547