[concurrency-interest] Timestamps-based ConcurrentMap

David Holmes dcholmes at optusnet.com.au
Thu Mar 9 19:22:35 EST 2006

It sounds like you want to make an atomic snapshot of the map and iterate
over that. But atomic access to ConcurrentHashMap can't be done - there is
no global lock to grab, nor do you want one.

The timestamp idea seems only a partial solution depending on what your
constraints actually are: you can't stop entries being removed, you can only
skip entries that have been added since, if they appear.

Why not just use an iterator to make your own immutable snapshot that can
then be accessed by other threads. Any thread using the snapshot would have
to realize that entries may have since been removed from the map (assuming
application logic permits that). The snapshot would reflect the state of the
map between the iterator being constructed and the iteration being

David Holmes

> -----Original Message-----
> From: concurrency-interest-bounces at cs.oswego.edu
> [mailto:concurrency-interest-bounces at cs.oswego.edu]On Behalf Of Jean
> Morissette
> Sent: Friday, 10 March 2006 9:55 AM
> To: concurrency-interest at cs.oswego.edu
> Subject: [concurrency-interest] Timestamps-based ConcurrentMap
> Hi,
> In ConcurrentHashMap, iterators are designed to be used by only one
> thread at a time.  However, I would like to have a ConcurrentMap
> implementation where iterators could be used by many threads at time,
> in a consistent way.  These iterators should reflect the state of the
> map at the creation of the iterator, independently of the map update
> operations.
> Is-there a class somewhere that achieve this behaviour?  IMO, it would
> be a nice addition to j.u.concurrent package.  Or, is there any plan
> to create it in the future?
> Otherwise, I will try to develop it myself, maybe by assigning a
> timestamps to each entry and iterator. Or, do you have others
> suggestions/advices?
> Regards,
> Jean
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest

More information about the Concurrency-interest mailing list