JFreeChart抛出java.util.ConcurrentModificationException

时间:2017-09-13 20:08:46

标签: java exception jfreechart concurrentmodification

我目前正在使用JFreeChat来绘制一些带有Java的图表。实际绘图是一个非常大的项目的一部分,它不允许我轻松地包含更多代码。对我而言,似乎直接抛出了异常 来自JFreeChart组件。如果有人可以提供帮助,我将非常感激。有没有办法更详细地追踪抛出异常的位置?我读到异常通常在列表迭代的情况下抛出,同时从同一列表中删除元素(这不是我现在正在做的事情)。

Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException
    at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
    at java.util.ArrayList$Itr.next(ArrayList.java:851)
    at org.jfree.chart.plot.XYPlot.drawAnnotations(XYPlot.java:3972)
    at org.jfree.chart.plot.XYPlot.draw(XYPlot.java:3339)
    at org.jfree.chart.JFreeChart.draw(JFreeChart.java:1229)
    at org.jfree.chart.ChartPanel.paintComponent(ChartPanel.java:1624)
    at javax.swing.JComponent.paint(JComponent.java:1056)
    at javax.swing.JComponent.paintToOffscreen(JComponent.java:5210)
    at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1579)
    at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1502)
    at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:306)
    at javax.swing.RepaintManager.paint(RepaintManager.java:1272)
    at javax.swing.JComponent._paintImmediately(JComponent.java:5158)
    at javax.swing.JComponent.paintImmediately(JComponent.java:4969)
    at javax.swing.RepaintManager$4.run(RepaintManager.java:831)
    at javax.swing.RepaintManager$4.run(RepaintManager.java:814)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:814)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:789)
    at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:738)
    at javax.swing.RepaintManager.access$1200(RepaintManager.java:64)
    at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1732)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

最好的问候。

3 个答案:

答案 0 :(得分:2)

第3972行版本1.0.19中的drawAnnotations()来源here;它不起眼,通常功能正常。如果您无意中使您的顶级容器可见或更新了initial thread上的绘图数据集,则可能会出现问题。生成的更新事件将在event dispatch thread上执行,可能会导致竞争条件。 Swing要求您在event dispatch thread上构造和操作仅的Swing GUI对象。如果错误代码不明显,请尝试使用here显示的方法来检测潜在的违规行为。

答案 1 :(得分:1)

我会说你有另一个线程正在修改注释列表。 如果你可以在你的IDE中重现这个,在抛出这个异常时放一个断点(暂停vm中的所有线程),并在异常发生时检查其他线程。

请参阅Eclipse Conditional-Breakpoint. How to check if exception occurs?

答案 2 :(得分:1)

请看这个问题:

How to avoid "ConcurrentModificationException" while removing elements from `ArrayList` while iterating it?

这里的问题是类似的;堆栈跟踪中的ArrayList正在同时进行操作。上面的问题涉及删除元素,但多个线程的任何并发操作都会导致这种情况。 ArrayList不是线程安全的。

另一个值得关注的问题: How do I make my ArrayList Thread-Safe? Another approach to problem in Java?

如果这不是您的ArrayList,则可能是您调用的任何代码中的错误。