Hi everybody,

I have a basic question regarding modifying graphs and the synchronization of modifying actions. Given a mxGraph object and a mxGraphComponent displaying this graph, and assuming that both are part of a larger application that might even run in different threads. Given this setup there are in principal two ways by which the graph can be modified:

a) by user interaction (given that appropriate listeners and event handling mechanisms are installed etc.)

b) from inside of the program independent of any user interaction or event

My question is how to synchronize changes from both sides that appear simultaneously. Is there any mechanism that ensures that, e.g., methods like setCellStyle(...) act in a synchronized manner on the graph and that multiple calls of this routine targetting to the same cell do not interfere with each other?

I figured out that the methods beginUpdate() and endUpdate() of the mxGraphModel appear to be linked to this issue, however, I would expect that at least beginUpdate() should block in case that an update is already going on - what the routine appearantly does not. For the moment I occasionally get exceptions like the one below, if the program is trying to modify the graph while simultaneously user interactions triggering events take place:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at java.awt.BasicStroke.createStrokedShape(BasicStroke.java:306) at com.mxgraph.swing.handler.mxSelectionCellsHandler.refresh(Unknown Source) at com.mxgraph.swing.handler.mxSelectionCellsHandler$1.invoke(Unknown Source) at com.mxgraph.util.mxEventSource.fireEvent(Unknown Source) at com.mxgraph.util.mxEventSource.fireEvent(Unknown Source) at com.mxgraph.model.mxGraphModel$1.dispatch(Unknown Source) at com.mxgraph.model.mxGraphModel.endUpdate(Unknown Source) at com.mxgraph.swing.handler.mxConnectionHandler.mouseReleased(Unknown Source) at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:273) at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)...

So I think that I did not really get the point of synchronization.

I am glad about every hint, thanks in advance!

asked 19 Nov '12, 13:31

agm-dev's gravatar image

accept rate: 0%

Number 1 rule of Swing - Only modify the GUI in the event dispatch thread. This applies to everything in Swing.

If you're modifying the GUI outside of that thread, simple, don't :).


answered 19 Nov '12, 15:07

David's gravatar image

accept rate: 47%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 19 Nov '12, 13:31

Seen: 1,248 times

Last updated: 19 Nov '12, 15:07