如何在Java 8 Streams中修复IndexOutOfBoundException?

时间:2019-03-30 15:14:14

标签: java-8 java-stream

我试图在IntStream并行循环中更新外部地图。但是它在到达循环结束之前给出IndexOutOfBoundException。

IntStream.range(0, 16384).parallel().forEach(index -> {
String slotKey = String.valueOf(index);
slotMap.put(slotKey, cacheService.getCountOfKeysInSlots(index));
System.out.println(index);
}
);  

当i的值为16264时会产生错误,该值早于I的最终值(16384)

感谢有人帮助我解决问题。

0 个答案:

没有答案