Search code examples
javaparallel-processingjava-8concurrenthashmap

ConcurrentHashMap parallelismThreshold


The ConcurrentHashMap got a couple new methods. I have two questions regarding them:

  1. Why aren't they declared in ConcurrentMap?
  2. What exactly does the parallelismThreshold mean or do?

Solution

    1. These new methods seem to rely on implementation details specific to ConcurrentHashMap, but you would have to get an answer from the Java 8 authors to be sure. (they do browse SO)

    2. From the Javadoc of ConcurrentHashMap:

      These bulk operations accept a parallelismThreshold argument. Methods proceed sequentially if the current map size is estimated to be less than the given threshold. Using a value of Long.MAX_VALUE suppresses all parallelism. Using a value of 1 results in maximal parallelism by partitioning into enough subtasks to fully utilize the ForkJoinPool.commonPool() that is used for all parallel computations. Normally, you would initially choose one of these extreme values, and then measure performance of using in-between values that trade off overhead versus throughput.