Sumit Chakraborty
Sumit Chakraborty

Reputation: 13

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?

Upvotes: 1

Views: 2424

Answers (1)

Marcelo
Marcelo

Reputation: 4608

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.

Upvotes: 1

Related Questions