最近在看vipshop的Saturn,为更好跟踪分享Saturn saturn,简单修改启动代码,将classpath 中所有path自动设置为saturnLibDir.
只需要修改一个函数 :com.vip.saturn.job.executor.Main的setExecutorClassLoader,修改后代码如下
private void setExecutorClassLoader(ClassLoader executorClassLoader) throws MalformedURLException {
if (executorClassLoader == null) {
if (saturnLibDir!=null) {
List<URL> urls = getUrls(new File(saturnLibDir));
this.executorClassLoader = new SaturnClassLoader(urls.toArray(new URL[urls.size()]),
Main.class.getClassLoader());
}else
{
String path = System.getProperty("java.class.path");
String[] paths = path.split(";");
List<URL> urls =new ArrayList<URL>();
for (int i=0;i<paths.length;i++) {
File file = new File(paths[i]);
urls.add(file.toURI().toURL());
}
this.executorClassLoader = new SaturnClassLoader(urls.toArray(new URL[urls.size()]),
Main.class.getClassLoader());
}
this.executorClassLoaderShouldBeClosed = true;
} else {
this.executorClassLoader = executorClassLoader;
this.executorClassLoaderShouldBeClosed = false;
}
}