0

I have a variable

private volatile MultiMap myMap;

public void doProcessing {
    
     myMap = getValueFromMainThread()
     myForkJoinPool.submit(() -> readWithinMultipleThreads())


}

private void readWithinMultipleThreads() {
   readSomethingFrom(myMap.get)
}

I assume this might be enough and do not need myMap to be threadsafe as I read in the child thread and do not modify the state. I am also not sure if I would need volatile at all

HamoriZ
  • 2,370
  • 18
  • 38

1 Answers1

1

The volatile might be necesarry when you update the variable myMap while other threads read from it.

If you are just reading from the map you dont need a threadsafe map implementation.

What is the volatile keyword useful for?

SimGel
  • 293
  • 1
  • 10