Uploaded image for project: 'CDI Specification Issues'
  1. CDI Specification Issues
  2. CDI-501

Firing and consuming events should take place in the same thread

    Details

    • Type: Clarification
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 1.2.Final
    • Fix Version/s: 2.0-EDR1
    • Component/s: Events
    • Labels:
      None

      Description

      An event can be fired with a call to event.fireEvent(payload). CDI then calls all the observers for that event with the given payload.

      All the implementations call the annotated methods of the observers in the same thread as the one where the call to fireEvent() was made. In some cases the payload object is mutable, and the observers leverage that property to change its state.

      The issue is the following :

      • the payload object is not specified, it can then be mutable, non-synchronized etc...
      • it is not stated that the firing of the event and the consuming of the payload should occur in the same thread.

      So one could build an implementation where the consuming of the event occurs in different threads than the one where the fireEvent() was called. If the payload is mutated in the observer methods then visibility issues due to race conditions can arise.

      Side note : most of the time it is also assumed that the fireEvent() method returns when all the observers have been called and returned. This point is not specified. We can assume that other issues could arise when it is not the case.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                antoinesabot-durand Antoine Sabot-Durand
                Reporter:
                josepaumard José Paumard
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: