简体   繁体   中英

java.exe high cpu usage

I am using Netbeans 8.0.2 to develop a Java GUI which has a login form and a few other JInternalFrames inside a JFrame. Netbeans doesn't use high CPU but whenever I run the project and the windows open up, the cpu rises up to 90-93%. Can someone please tell me the cause of this?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM