java.exe高CPU使用率

时间:2015-09-14 10:32:36

标签: java netbeans jframe cpu

我正在使用Netbeans 8.0.2开发一个Java GUI,它在JFrame中有一个登录表单和一些其他JInternalFrame。 Netbeans没有使用高CPU,但每当我运行项目并打开窗口时,cpu上升到90-93%。有人可以告诉我原因吗?

1 个答案:

答案 0 :(得分:1)

There are some serious issues with your code, but the immediate culprit for high CPU usage is this:

while(!AccountoBot.loggedIn)
    {
        jl.setText("LOG IN TO VIEW THIS SECTION");
        jl.setHorizontalAlignment(CENTER);
        add(jl);
    } 

You are on an infinite loop (at least until someone logs in) setting an UI element. It won't block the UI (because you started it in another thread), but will cause a very high CPU consumption.

You should check the official tutorial on Swing and threads and maybe, after you've improved a bit, post on CodeReview to get a more detailed feedback for your code.