Java SwingWorker still uses 98% CPU after it's done.
- by RemiX
I am new to the Java SwingWorker class, but I'm trying to get it to do some stuff in the background. That part works already, but now, when it is finished, the Windows Task Manager still shows that 70-98% of the CPU is still being used. Before I hit the 'Start' button it is only 3-15% and after I close the program it returns to those values.
But what is still happening when the SwingWorker already reported being done??
I'll give you a simplified version of my code:
I have this StereoProcessor extending SwingWorker, with doInBackground():
yLoop for(some values y)
{
for(some values x)
{
if(isCancelled())
break yLoop;
else
{
setProgress(to some value);
// do some non-SingWorker-related stuff
}
}
}
return returnValue;
I call to this process through another code:
stereoProcessor.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if(evt.getPropertyName().equals("state"))
if(evt.getNewValue().equals(StereoProcessor.StateValue.DONE)
{
// do stuff
}
}
}
});
stereoProcessor.computeSomething(); // this method calls execute()
That's about it, so I don't understand what it keeps doing. I tried putting some System.outs in the code in different places, but all stopped printing after a while.
Does anyone know what's going on?
Edit: I noticed the CPU also keeps running after a simple call to a method in StereoProcessor that doesn't even call execute()...