Multi-threading and yFiles' graph structures |
| Applies to: yFiles for Java 2.8, 2.7, 2.6, 2.5, 2.4, 2.3, 2.2, 2.1, 2.0 |
Categories this article belongs to:
| yFiles for Java | > Other |
Typically, there is (at least) one graph that is displayed to a user, most probably using a Graph2DView
, and modified concurrently. Since Graph2DView
is a SWING component, the general rule for threads and SWING components applies: "All modifications have to be done within SWING's event dispatch thread (EDT)." Aside from the obvious structural modifications such as adding or deleting elements to or from the graph, this includes any aspects that affect the graph's visual representation such as any modifications made to node or edge realizers.
java.awt.EventQueue's static methods invokeAndWait(Runnable) and invokeLater(Runnable) may be used to enforce the above rule.
Another common use case is to calculate graph layouts in a separate thread. "How to layout a graph in a separate thread" describes the basic steps necessary for that approach. In summary, these steps are
- create a copy of your main graph
- calculate a layout for the copy in a separate thread
- update your main graph according to the geometry data of the copy
Using CopiedLayoutGraph
In a nutshell, it is important to synchronize all modifications made to a graph. For graphs that are displayed using Graph2DView
this means handling all changes in the EDT. Additionally, when calculating layouts in a separate thread using CopiedLayoutGraph
, the original graph may not be modified while the copy is in use.
| Keywords: | layout - thread - threading - multi threading - multi-threading - multithreading |


