Race condition occurring during use of Parallel Streams and Atomic Variables
问题 When the following piece of code is getting executed I am getting exceptions in a random manner. byte[][] loremIpsumContentArray = new byte[64][]; for (int i = 0; i < loremIpsumContentArray.length; i++) { random.nextBytes(loremIpsumContentArray[i] = new byte[CONTENT_SIZE]); } AtomicBoolean aBoolean = new AtomicBoolean(true); List<Long> resultList = IntStream.range(0, 64* 2) .parallel() .mapToObj(i -> getResult(i, aBoolean, repositoryPath, loremIpsumContentArray )) .collect(Collectors.toList()