Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConcurrentModificationException #81

Closed
seewip opened this issue Sep 10, 2014 · 15 comments
Closed

ConcurrentModificationException #81

seewip opened this issue Sep 10, 2014 · 15 comments

Comments

@seewip
Copy link

seewip commented Sep 10, 2014

My app containing xchart will get the ConcurrentModificationException (as in the stacktrace below) once every few hours or when the computer wakes up from sleep/hibernation. The graph is a live area-chart updated each second.

Stacktrace:

Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException
    at java.util.ArrayList$Itr.checkForComodification(Unknown Source)
    at java.util.ArrayList$Itr.next(Unknown Source)
    at com.xeiam.xchart.internal.chartpart.PlotContentLineChart.paint(PlotContentLineChart.java:117)
    at com.xeiam.xchart.internal.chartpart.Plot.paint(Plot.java:84)
    at com.xeiam.xchart.internal.chartpart.ChartPainter.paint(ChartPainter.java:111)
    at com.xeiam.xchart.internal.chartpart.ChartPainter.paint(ChartPainter.java:70)
    at com.xeiam.xchart.Chart.paint(Chart.java:94)
    at com.xeiam.xchart.XChartPanel.paintComponent(XChartPanel.java:89)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JComponent.paintToOffscreen(Unknown Source)
    at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
    at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
    at javax.swing.RepaintManager.paint(Unknown Source)
    at javax.swing.JComponent._paintImmediately(Unknown Source)
    at javax.swing.JComponent.paintImmediately(Unknown Source)
    at javax.swing.RepaintManager$4.run(Unknown Source)
    at javax.swing.RepaintManager$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
    at javax.swing.RepaintManager.access$1300(Unknown Source)
    at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$400(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
@timmolter
Copy link
Member

In which way are you updating the series data?

@seewip
Copy link
Author

seewip commented Sep 10, 2014

First at all, my modified JFrame looks like this:

XChartPanel chartPanel;
Chart chart;

public modifiedJFrame() {
        chart = new ChartBuilder().chartType(ChartType.Area).yAxisTitle("Time (ms)").theme(ChartTheme.GGPlot2).build();
        chart.addSeries(SERIES1_NAME, new int[] {0}, new int[] {0});
        chart.addSeries(SERIES2_NAME, new int[] {0}, new int[] {0});

        chart.getStyleManager().setChartTitleVisible(false);
        chart.getStyleManager().setXAxisTitleVisible(false);
        chart.getStyleManager().setXAxisTicksVisible(false);
        chart.getStyleManager().setLegendPosition(LegendPosition.InsideN);
        chart.getStyleManager().setPlotBackgroundColor(new Color(0,0,0,0));
        chart.getStyleManager().setChartBackgroundColor(new Color(0,0,0,0));
        chartPanel = new XChartPanel(chart);
        // Adding chart to jframe and doing some other things...
}

Series are updated from Timer scheduled to 1 second and the TimerTask looks like this:
(where window is a pointer to the modified jframe's object and series name has been defined earlier)

List<Integer> series1_Y = new ArrayList<Integer>();
List<Integer> series1_X = new ArrayList<Integer>();
List<Integer> series2_Y = new ArrayList<Integer>();
List<Integer> series2_X = new ArrayList<Integer>();

// Do some work on lists and make sure they are not empty

window.chartPanel.updateSeries(window.SERIES1_NAME, series1_X, series1_Y);
window.chartPanel.updateSeries(window.SERIES2_NAME, series2_X, series2_Y);

This is the only code that updates the series in my app.

@timmolter
Copy link
Member

This is proving hard for me to debug since I cannot repeat the exception. Anyway, I believe the problem is occurring when two threads (the main GUI thread and the timer thread) are reading/writing to the series data array(s) at the same time. Can you try something for me?

Instead of ArrayLists, can you try three different options?

  1. ConcurrentLinkedQueue
  2. Vector
  3. Collections.synchronizedList(new ArrayList())

Please let me know if that helps. If so, I can perhaps come up with a solution internal to XChart.

@seewip
Copy link
Author

seewip commented Sep 18, 2014

First at all, I've doubled check my code, looking for code in other threads that might modify the list but found none, except for XChart itself (which is on other thread). I've tried changing ArrayList to Vectors, but the exception still occurs. I've looked at ConcurrentLinkedQueue, but it would require some code to be changed, so I have skipped it for now. Right now I am testing the synchronizedList method. I will let you know if I get anything new.

@seewip seewip closed this as completed Sep 18, 2014
@seewip
Copy link
Author

seewip commented Sep 27, 2014

That took me longer than I expected, however even with synchronizedList method the error still persists. Anything else I can do, except for the ConcurrentLinkedQueue method? I can try running the x-chart demo for a longer time and check whether it shows this error after hibernation.

@seewip seewip reopened this Sep 27, 2014
@timmolter
Copy link
Member

One question. Is it only occurring after waking up from hibernation?

@seewip
Copy link
Author

seewip commented Sep 30, 2014

Previously it took place randomly, though it was very rare and most of errors occured after waking up, but lately the errors only occur after waking up.

@timmolter
Copy link
Member

Also, what OS?

@seewip
Copy link
Author

seewip commented Sep 30, 2014

Windows 8.1. I didn't do long-run tests on other machines yet.

@timmolter
Copy link
Member

Thanks for the additional info. I googled about threads and waking up computers and came up completely empty-handed. Have you found anything?

@seewip
Copy link
Author

seewip commented Oct 1, 2014

Not really, i will do some testing on Win 7 and Ubuntu and let you know.

@timmolter
Copy link
Member

OK, thanks.

@rizwanali89
Copy link

Hi,
Seewip and timmolter....
I got the same situation.... After this error occur my java based GUI freez. when I minimize and then maximize any xchart or my java GUI jfram it get black no thing shown in GUI except black color.

@rizwanali89
Copy link

I thing there is a bug in xchart API we are using. Actually I rendered a graph based on values comes from server in fraction of seconds.

@timmolter
Copy link
Member

Use a CopyOnWriteArrayList to store your data rather than ArrayLists. I'll update the real-time demos.

timmolter added a commit that referenced this issue Jul 11, 2015
…t in the demos and the exception disappears.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants