假设你做的很简单:
public class Main {
public static void main(String[] args) {
long started = System.currentTimeMillis();
try {
new URL(args[0]).openConnection();
} catch (Exception ignore) {
}
System.out.println(System.currentTimeMillis() - started);
}
}
Run Code Online (Sandbox Code Playgroud)
现在使用http:// localhost as 运行它args[0]
它需要~100 msec完成.
需要5000+ msec.
现在在linux或docker中运行相同的东西:
~100 msec~350 msec为什么是这样?为什么平台之间有这么大的差异?你能为这个做什么?
对于长时间运行的应用程序服务器和具有自己长而重的初始化序列的应用程序,这5秒可能无关紧要.
然而,有很多应用程序,这个最初的5秒"挂起"很重要,可能会令人沮丧......