SPI机制破坏双亲委派模型
2021-04-22 20:31:40 2 举报
Java SPI机制源码流程
作者其他创作
大纲/内容
初始化DriverManager.javastatic { loadInitialDrivers(); println(\"JDBC DriverManager initialized\");}
loadedDrivers.iterator();
lookupIterator.next();
java.util.ServiceLoader.LazyIterator#next
java.sql.DriverManager
ServiceLoader.load(Driver.class);
程序启动(设置上下文类加载器)public Launcher(){ ... this.loader = Launcher.AppClassLoader.getAppClassLoader(var1); Thread.currentThread().setContextClassLoader(this.loader); ... }
Connection conn = DriverManager.getConnection(\"jdbc:mysql://localhost:3306/mydb?xxxx\
sun.misc.Launcher#Launcher
java.util.ServiceLoader
SPI机制破坏双亲委派模型 >
hasNextService():作用:判断是否有下一个Service,且将META-INF/services/*目录下的文件读取出来。
java.util.ServiceLoader.LazyIterator#nextService
driversIterator.next();
ServiceLoader<Driver> loadedDrivers = ServiceLoader.load(Driver.class);Iterator<Driver> driversIterator = loadedDrivers.iterator();try{ while(driversIterator.hasNext()) { driversIterator.next(); } } catch(Throwable t) { // Do nothing}
加载并初始化驱动loadInitialDrivers();
0 条评论
下一页