Java Code Examples for java.util.concurrent.ConcurrentHashMap.forEachValue()

The following are Jave code examples for showing how to use forEachValue() of the java.util.concurrent.ConcurrentHashMap class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10   File: ConcurrentHashMap8Test.java   View Source Code Vote up 6 votes
/**
 * forEachValueSequentially traverses all values
 */
public void testForEachValueSequentially() {
    LongAdder adder = new LongAdder();
    ConcurrentHashMap<Long, Long> m = longMap();
    m.forEachValue(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue()));
    assertEquals(adder.sum(), SIZE * (SIZE - 1));
}
 
Example 2
Project: openjdk-jdk10   File: ConcurrentHashMap8Test.java   View Source Code Vote up 6 votes
/**
 * forEachValueInParallel traverses all values
 */
public void testForEachValueInParallel() {
    LongAdder adder = new LongAdder();
    ConcurrentHashMap<Long, Long> m = longMap();
    m.forEachValue(1L, (Long x) -> adder.add(x.longValue()));
    assertEquals(adder.sum(), SIZE * (SIZE - 1));
}