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

Add CopyOnWriteArrayList.snapshot()

    Details

      Description

      A DESCRIPTION OF THE REQUEST :
      A reader of CopyOnWriteArrayList most likely needs to see a consistent view of the list for multiple operations. It'll be nice to have a `snapshot()` method that returns a read only List on the current array.

      See David M. Lloyd's suggestion and implementation -- http://cs.oswego.edu/pipermail/concurrency-interest/2009-March/005926.html

      CopyOnWriteArraySet can also benefit from a `snapshot()` method.

      JUSTIFICATION :
      Recently I've seen a couple of questions on stackoverflow.com asking for returning read only views of an underlying list that may be mutated by the owner. While CopyOnWriteArrayList provides good concurrency protection, it does not provide consistency during access (unless using iterator()). A snapshot() method is going to help a lot of use cases.

      [1] http://stackoverflow.com/questions/35287565


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                martin Martin Buchholz
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated: