So I was trying to get at least the code for adding and removing from the dataset out of the event dispatch thread. I thought, by synchronizing on the series, this could be made threadsafe. So this is, what I tried to do in pseudocode:
Code: Select all
synchronized(dataSeries){
dataSeries.setNotify(false);
dataSeries.add();
dataSeries.remove();
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
synchronized(dataSeries){
dataSeries.setNotify(true);
chartPanel.restoreAutoBounds();
domainAxis.setRange(range);
domainAxis.setRange(range);
rangeAxis.configure();
renderer.setCandleWidth(candleWidth);
(etc...)
}
}
I am a bit puzzled, because I thought restricting access to dataSeries should be enough but it is not. Should I use another object to synchronize on? Or is there a better way to split data adding, removal, and chart drawing?