通过Class.forName动态加载类时,本地直接通过IDE执行程序,但是线上则是mvn打包之后,通过命令行执行程序,然后发现,当发生ClassNotFoundException时,两种执行方式的花费时间相差较大,本地执行只需要10ms左右,命令行的执行方式则要花费10倍左右,请问有人知道是因为什么原因吗?完整代码如下:
public static void main(String[] args) {
long startTs = System.currentTimeMillis();
for (int i = 0; i < 3000; i++) {
try {
Class.forName("com.baidu.galaxy.queryservice.service.filter.A");
} catch (ClassNotFoundException e) {
}
}
long endTs = System.currentTimeMillis();
System.out.println(endTs - startTs);
}