public static void main(String[] args)
{
Map<Long, Long> map = IntStream.range(0, 1_000_000)
.parallel()
.mapToObj(i -> System.nanoTime())
.collect(Collectors.groupingBy(x -> x, Collectors.counting()));
map.entrySet()
.stream()
.max(Entry.comparingByValue())
.ifPresent(e -> System.out.printf("%X => %d\r\n", e.getKey(), e.getValue()));
}
prints (i.e.):
69C57829077 => 24
I thought that two calls in the same VM (even if in different threads) should return two different values.
In this case, a single value is returned by 24 (!!) invocations.
How can this happen?
P.S. I'm on Win10 x64