Uploaded image for project: 'JSword'
  1. JSword
  2. JS-263

Replace EventListenerList with CopyOnWriteArrayList

    Details

    • Type: Improvement
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.6
    • Fix Version/s: 1.7
    • Component/s: o.c.common.util
    • Labels:
      None

      Description

      The o.c.c.util.EventListenerList is far more complicated than is needed. It allows for more than one type of listener to be in the list.

      CopyOnWriteArrayList provides the same of MT safety and removes the unneeded complexity.

      The added benefit is that external synchronization on the list can be removed. It probably didn't need to be there in the first place.

        Attachments

          Activity

          Hide
          chrisburrell Chris Burrell added a comment -

          Presumably these are event listeners are added by the user of the library? as opposed to JSword internally using them? Obviously, we only want to do this if it's rarely used - as copying a list of stuff many times would result in un-necessary memory allocations if it were use many times during an operation.

          Otherwise, all up for reducing complexity. I'd personally favour waiting for Java 6 and use http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html

          What do you think?

          Show
          chrisburrell Chris Burrell added a comment - Presumably these are event listeners are added by the user of the library? as opposed to JSword internally using them? Obviously, we only want to do this if it's rarely used - as copying a list of stuff many times would result in un-necessary memory allocations if it were use many times during an operation. Otherwise, all up for reducing complexity. I'd personally favour waiting for Java 6 and use http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html What do you think?
          Hide
          dmsmith DM Smith added a comment -

          The EventListenerList is used in a dozen places in JSword to manage listeners of a single type per list.
          Every time any action is done on the list, a copy of the list is made.

          Moving to CopyOnWriteArrayList is a significant performance improvement as it only does a copy on write. I've been running with it as the listener list in the Progress meter and it has solved the synchronization deadlock (which I thought I solved earlier, but merely minimized it) and I can index Bibles faster than I can get to the next. Before the change, I could stack a half dozen or so.

          The big gain is that the listener lists seldom change. So it is almost like using an unsynchronized list.

          I discovered the usage when researching synchronization problems for listener lists.

          So, I'd rather not wait. The choice right now is either leaving EventListenerList or use CopyOnWriteArrayList. We can certainly revisit when we get to Java 6.

          Show
          dmsmith DM Smith added a comment - The EventListenerList is used in a dozen places in JSword to manage listeners of a single type per list. Every time any action is done on the list, a copy of the list is made. Moving to CopyOnWriteArrayList is a significant performance improvement as it only does a copy on write. I've been running with it as the listener list in the Progress meter and it has solved the synchronization deadlock (which I thought I solved earlier, but merely minimized it) and I can index Bibles faster than I can get to the next. Before the change, I could stack a half dozen or so. The big gain is that the listener lists seldom change. So it is almost like using an unsynchronized list. I discovered the usage when researching synchronization problems for listener lists. So, I'd rather not wait. The choice right now is either leaving EventListenerList or use CopyOnWriteArrayList. We can certainly revisit when we get to Java 6.
          Hide
          chrisburrell Chris Burrell added a comment -

          Sounds good Let's go for it.

          Show
          chrisburrell Chris Burrell added a comment - Sounds good Let's go for it.

            People

            • Assignee:
              dmsmith DM Smith
              Reporter:
              dmsmith DM Smith
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: