Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5031664

Increase thread safety of EventListenerList

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b34
    • CPU:
      x86
    • OS:
      windows_2000

      Description


      Name: jl125535 Date: 04/14/2004


      FULL PRODUCT VERSION :
      java version "1.4.2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
      Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)

      A DESCRIPTION OF THE REQUEST :
      EventListenerList should synchronize getListeners() and getListenerList() methods to complement the synchronized add() and remove() methods.

      I suggest EventListenerList be reimplemented using AWTEventMulticaster which is thread safe.

      JUSTIFICATION :
      Not synchronizing getListeners() and getListenerList() undoes the benefit of synchronizing the add and remove methods, because removing a listener while processing getListeners() can result in ArrayOutOfBoundsExceptions.
      Also the re-assignment of the listener list at the bottom of the add and remove is not atomic so using the return of getListenerList() is problematic in a multi-threaded application.

      This means for example you cannot reliably remove a Document listener using a program thread, while the document is being updated by the user on the Swing thread.

      (Incident Review ID: 246793)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              serb Sergey Bylokhov
              Reporter:
              jleesunw Jon Lee (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: