Cycle in Activity Diagram

The activity diagram contains a forbidden construction, namely, a cycle or a loop.

Cycle is formed when in one activity step a token flows from a merge node (or a connector merge) through its outgoing edge, other activity nodes and edges, and back to the merge node. Within that same step, the incoming token will traverse further to the merge's outgoing edge again (a merge node or a connector merge only has exactly one outgoing edge). Intuitively, the flow never ends in a stable position and, therefore, this type of construction is an error.

It might be more difficult to see a cycle when connector merges are involved. Choose one connector merge and move all the other connector merges into the one you chose.



An example of this type of error is depicted in the following figure. The elements that form a cycle are highlighted with yellow background.

Possible Solution(s)

Depending on the behavior of your application, there are several possible solutions. The basic idea to correct this problem is to cut the activity step containing the loop. For example, you can use a 0ms timer as shown below. This interruption splits the activity steps into two parts, so that also other behavior has the chance of being executed in between.

Another alternative is shown in the following:

Here we use block Periodic Timer (a) from the Timers library instead of 0ms timer. Moreover, we also add a second operation display (b) and remove the merge node between the reception and the upper operation (c).

These two correct constructions behave similarly (the only difference may be the duration of the timers). First, a String obtained from the reception Message is displayed. Thereafter a new String from operation newMessage is displayed periodically.