[concurrency-interest] Traversal and removing elements from ConcurrentskipListSet

Michael Kuhlmann concurrency at kuli.org
Tue May 16 09:54:51 EDT 2017


Hi Dileep,

please read the JavaDoc of ConcurrentSkipListSet. It refers to the
"weakly consistent" section of the package JavaDoc. This states:

***
[Iterators] are guaranteed to traverse elements as they existed upon
construction exactly once, and may (but are not guaranteed to) reflect
any modifications subsequent to construction.
***

So yes, this should work as expected as long as every e is unique.
However, it's always better to directly use the Iterator instead of the
short for loop, and call remove() on the iterator. This will work for
all modifiable Iterable implementations, and it will work for multiple
entries which are equal to each other.

-Michael


Am 16.05.2017 um 14:43 schrieb Dileep Mandapam:
> Hi 
> 
> Environment details:-
> java version "1.8.0_131"
> Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
> Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
> 
> 
> 
>  Removing an element while traversal . Sometimes elements are not
> removing from concurrentskiplistset. 
> 
> for( Element e : concurrentskiplistsetcollection) {
>  
>      if ( e is to be removed) {
>             concurrentskiplistset.remove(e);
>     }
> 
> }
> 
> My question is safe to use above to pattern to remove elements ?
> -- 
> Regards
> Dileep M
> 
> 
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
> 



More information about the Concurrency-interest mailing list