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



    • Clarification
    • Status: Resolved (View Workflow)
    • Major
    • Resolution: Done
    • 1.2.Final
    • 2.0-EDR1
    • Events
    • None


      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.




            asabotdu@redhat.com Antoine Sabot-Durand (Inactive)
            josepaumard José Paumard (Inactive)
            0 Vote for this issue
            4 Start watching this issue