2

I'am trying to use chronicleMap.parallelStream:

myChronicleMap.entrySet().parallelStream().forEach((entry) -> {
   process(entry); //heavy process 
}

I got the following exception.

java.lang.IllegalStateException: ChronicleMap ... Iterator should be accessed only from a single thread

Any idea how to use chronicleMap and parallelStream? Thanks

kem
  • 407
  • 1
  • 6
  • 20

1 Answers1

1

If chronicle does not support parallel streams, then you will have to copy its contents into a map implementation which does.

Map<?, ?> mapCopy = myChronicleMap.entrySet()
                                  .stream()
                                  .collect(Collectors.toMap(Entry::getKey, Entry::getValue));
mapCopy.entrySet().parallelStream().forEach(this::process);
Joe C
  • 15,324
  • 8
  • 38
  • 50
  • 1
    I am using chronicle map because I need performant off-heap maps. https://github.com/OpenHFT/Chronicle-Map – kem Sep 24 '17 at 14:13
  • 3
    Well, you have three options. First option is to copy to a map type which supports parallel streams. Second option is to forget about parallel streams entirely and fall back to standard executor services. Third option is to contribute to OpenHFT to allow it to support parallel streams. – Joe C Sep 24 '17 at 14:15