开发者

pause for the Event Dispatcher

I've got a (primarily) single threaded application which updates a swing chart component (jfreechart) as it goes.

since all updates to the chart are done on the event dispatching thread, the que of tasks is getting too large and the chart is not updating in time with the code that is updating it.

is there a way to pause every so often so that the event dispatching thread can catch开发者_StackOverflow社区 up?

my first inclination would be to que a dummy task via SwingUtilities.invokeAndWait... could it be as simple as that?

cheers, p.


The dummy task would work, but maybe you could consider skipping some updates in the data-generating thread.

It depends on exactly what you are doing. Is your goal to compute something as fast as possible and update the GUI along the way, or are you trying to create a nice GUI that demonstrates some data analysis?

If it's the former then you really don't want to block waiting for the GUI to update - it will just slow down your computation. In that case just skip some updates and coalesce them into less frequent, larger updates.

If it's the latter then invokeAndWait will probably do the trick.


One approach is to decouple the update rates: update the data model asynchronously and update the view at a lower, adjustable rate. This example uses javax.swing.Timer to effect periodic updates, but a fixed ratio is an alternative. In the case of JFreeChart, the fireSeriesChanged() method of DynamicTimeSeriesCollection should give you necessary control.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜