Removing the synchronized added in the diff you mentioned does indeed eliminate the GUI lag; however, I presume those synchronized's are needed?
On a broader look: When the GUI renders, it gets the most current values from BandwidthController by-way-of SWDownloadFile . This causes the EventDispatchThread to block until it can retrieve this value from the data transfer thread.
As a test, I implemented a cache (see below). This showed a measurable improvement in GUI response.
I believe the ultimate solution would be to have SWDownloadFile listen to BandwidthController to receive updated values when available /instead of/ having SWDownloadFile query BandwidthController for each request and thus blocking.
Comments?
Code:
public static class EdtCache
{
private final SWDownloadFile download ;
private final long updateRate ;
private long lastUpdate ;
// private int shortTermTransferRate ;
private int longTermTransferRate ;
private long transferSpeed ;
private long downloadThrottlingRate ;
public EdtCache(SWDownloadFile download, long updateRate)
{
this.download = download;
this.updateRate = updateRate;
update();
}
private void update()
{
try {
// shortTermTransferRate = download.getShortTermTransferRate ();
longTermTransferRate = download.getLongTermTransferRate ();
transferSpeed = download.getTransferSpeed ();
downloadThrottlingRate = download.getDownloadThrottlingRate ();
lastUpdate = System.currentTimeMillis();
} catch (RuntimeException re) {
re.printStackTrace();
throw re;
}
}
private boolean needsUpdate() { return System.currentTimeMillis() - lastUpdate > updateRate; }
// public int getShortTermTransferRate()
// {
// if (needsUpdate()) update();
// return shortTermTransferRate;
// }
public int getLongTermTransferRate()
{
if (needsUpdate()) update();
return longTermTransferRate;
}
public long getTransferSpeed()
{
if (needsUpdate()) update();
return transferSpeed;
}
public long getDownloadThrottlingRate()
{
if (needsUpdate()) update();
return downloadThrottlingRate;
}
}
Cheers,
M. V`Chante