// iterate safely (& quickly) in the face of concurrent modifications static <A> IterableIterator<A> concurrentlyIterateSet(final NavigableSet<A> set) { fO mutex = collectionMutex(set); class ConcurrentlyIterateSet extends F0<A> { Iterator<A> it = set.iterator(); A key; A get() { synchronized(mutex) { try { if (!it.hasNext()) null; ret key = it.next(); } catch (ConcurrentModificationException e) { print("Re-iterating"); it = set.tailSet(key, false).iterator(); if (!it.hasNext()) null; ret key = it.next(); // Can't throw another exception } } } } ret iteratorFromFunction(new ConcurrentlyIterateSet); }
Began life as a copy of #1012173
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1013140 |
Snippet name: | concurrentlyIterateSet |
Eternal ID of this version: | #1013140/4 |
Text MD5: | 2ccd90b7cb6a7de305ce52f0072ab235 |
Author: | stefan |
Category: | javax / collections |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-01-12 11:18:33 |
Source code size: | 754 bytes / 23 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 402 / 453 |
Version history: | 3 change(s) |
Referenced in: | [show references] |