【发布时间】:2016-07-19 10:32:00
【问题描述】:
我在加载任何类型的摆动组件时都遇到了问题,现在加载时间太长了大约一天。我尝试使用不同的 IDE,我更新了 Java JDK,但是任何类型的 Swing 组件都需要很长时间才能加载,我目前正在我的引擎中使用它来加载项目并保存,但是显示时间太长了,所以我创建了一个只执行以下操作的空程序:
import javax.swing.JOptionPane;
public class main {
public main() {
}
public static void main(String[] args) {
long now = System.currentTimeMillis();
int result = JOptionPane.showOptionDialog(null, "Save before quitting ?", "Red Engine", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
System.out.println(System.currentTimeMillis() - now + "ms");
}
}
这是结果:5015ms 所以加载它需要五秒钟,我也有同样的问题,只是初始化一个 JFrame。
import javax.swing.JFrame;
public class main {
public main() {
}
public static void main(String[] args) {
long now = System.currentTimeMillis();
JFrame frame = new JFrame();
System.out.println(System.currentTimeMillis() - now + "ms");
}
}
这是结果:4505ms
那么 Java 到底发生了什么?这太令人沮丧了。我正在使用 jdk1.8.0_77 顺便说一句。
感谢您的帮助。
【问题讨论】:
-
因为它必须启动事件调度线程并在核心操作系统中建立所需的连接,所以这可能并不那么令人惊讶。尝试从 EDT 的上下文中创建你的 UI,看看这是否会有所作为。更多详情请见Initial Threads
标签: java performance swing constructor jframe