Provide thread-safe and concurrent sequenced collections with insertion order?

Sebastian Fischer mail at sebfisch.de
Thu Nov 2 11:56:23 UTC 2023


Hello.

I am new to this list so might have missed previous discussion about this
but could not find what I was looking for in the archives.

The Sequenced collections JEP adds the following static methods to
java.util.Collections.

- unmodifiableSequencedCollection
- unmodifiableSequencedSet
- unmodifiableSequencedMap

However, the set of static methods returning thread-safe versions of their
arguments (like synchronizedCollection, synchronizedSet, and
synchronizedMap) has not been extended.

As a consequence, I don't see a straightforward way to create thread-safe
sequenced sets or maps where encounter-order corresponds to insertion order
(like LinkedHashSet or LinkedHashMap) and access them as SequencedSet or
SequencedMap.

When using the available methods mentioned above, the result is not a
sequenced type.

For predefined sets and maps where encounter order corresponds to natural
order, there are the following methods in java.util.Collections.

- synchronizedNavigableSet
- synchronizedNavigableMap
- synchronizedSortedSet
- synchronizedSortedMap

However, these methods cannot be used with LinkedHashSet or LinkedHashMap.

The following methods would be useful in order to create thread-safe
sequenced collections where encounter order is insertion order, but they
are currently not provided.

- synchronizedSequencedCollection
- synchronizedSequencedSet
- synchronizedSequencedMap

What are the reasons for or against adding these methods?

There are also no implementations of concurrent sequenced sets and maps
where encounter order is insertion order in java.util.concurrent. All of
the provided concurrent sequenced sets and maps are based on natural order,
and consequently do not support addFirst, and so on.

Are there plans to add concurrent sequenced collections that support the
whole interface of sequenced collections?

Kind regards,
Sebastian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20231102/ac837c80/attachment.htm>


More information about the core-libs-dev mailing list