strongbox

Race condition occurring during use of Parallel Streams and Atomic Variables

不羁岁月 提交于 2021-02-18 18:01:14
问题 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()

Race condition occurring during use of Parallel Streams and Atomic Variables

孤人 提交于 2021-02-18 17:59:25
问题 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()