Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8179942

"ConcurrentHashMap()" creates a new, empty map with the default initial table size less than 16.

XMLWordPrintable

      FULL PRODUCT VERSION :
      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)

      ADDITIONAL OS VERSION INFORMATION :
      MINGW64_NT-10.0 DESKTOP-M49HTNK 2.5.0(0.295/5/3) 2016-03-31 18:47 x86_64 Msys

      A DESCRIPTION OF THE PROBLEM :
      As per the documentation, "ConcurrentHashMap()" creates a new, empty map with the default initial table size (16).
      However, I believe that the default size of it is much smaller.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      http://stackoverflow.com/questions/43774947/concurrenthashmap-and-fibonacci-numbers-inconsistent-result


      REPRODUCIBILITY :
      This bug can be reproduced rarely.

      ---------- BEGIN SOURCE ----------
      static Map<Integer, Integer> concurrentMap = new ConcurrentHashMap<>();

      public static void main(String[] args) {
      int num = 16;
      System.out.println("Fibonacci result for " + num + " is " + fibonacci(num));
      }

      static int fibonacci(int i) {
      if (i == 0)
      return i;

      if (i == 1)
      return 1;

      return concurrentMap.computeIfAbsent(i, (key) -> {
      System.out.println("Value is " + key);
      return fibonacci(i - 2) + fibonacci(i - 1);
      });
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      static Map<Integer, Integer> concurrentMap = new ConcurrentHashMap<>(16);

      SUPPORT :
      YES

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: