Skip to content

Commit

Permalink
readLock
Browse files Browse the repository at this point in the history
  • Loading branch information
tlrx committed Dec 10, 2020
1 parent 58b7bd9 commit 082e0c8
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -653,15 +653,15 @@ public void remove() {

/**
* Performs an action for each cache entry in the cache. While iterating over the cache entries this method is protected from mutations
* that occurs within the same cache segment by acquiring the segment's writing lock during all the iteration. As such, the specified
* that occurs within the same cache segment by acquiring the segment's read lock during all the iteration. As such, the specified
* consumer should not try to modify the cache. Modifications that occur in already traveled segments won't been seen by the consumer
* but modification that occur in non yet traveled segments should be.
*
* @param consumer the {@link Consumer}
*/
public void forEach(BiConsumer<K, V> consumer) {
for (CacheSegment<K, V> segment : segments) {
try (ReleasableLock ignored = segment.writeLock.acquire()) {
try (ReleasableLock ignored = segment.readLock.acquire()) {
for (CompletableFuture<Entry<K, V>> future : segment.map.values()) {
try {
if (future != null && future.isDone()) {
Expand Down

0 comments on commit 082e0c8

Please sign in to comment.