Consider the following simple method which is part of an appication with Swing gui:
public void updateFromGoogle(int action) {
startTime = System.currentTimeMillis();
model.updateFromGoogle(action);
System.out.println("Total run time "
+ (System.currentTimeMillis()-startTime));
}
Run time i=of the above method is consistently under 1 milli.
If I add to the method a SwingWorker
that does nothing:
public void updateFromGoogle(int action) {
startTime = System.currentTimeMillis();
SwingWorker sw = new SwingWorker<Boolean, Void>(){
@Override
protected Boolean doInBackground() throws Exception {
System.out.println("");
System.out.println("Swing worker start after "
+ (System.currentTimeMillis()-startTime));
return null;
}
@Override
public void done() {
System.out.println("Swing worker finished after "
+ (System.currentTimeMillis()-startTime));
}
};
sw.execute();
model.updateFromGoogle(action);
System.out.println("Total run time "
+ (System.currentTimeMillis()-startTime));
}
Occasionally I can see that the SwingWorker
starts after a very long time, for example (millis):
Swing worker start after 19734
Swing worker finished after 19767
Questions:
1. Does it suggest that some other long task is Occasionally running on the Event Dispatch Thread ?
2.How do I investigate which task is causing it ?
Edit: Following comment I installed jvisualvm
that shows that SwingWorker
uses a pool of 8 threads :