My use case is I have a file monitor that watches files, storing those files as custom objects in Map[Path, MyObject](). When any of files are updated, it will update Map accordingly. Meanwhile multiple threads will have access to Map, checking if corresponded Path exists or not, then perform necessary operations such as obtaining the object and then executing some methods and so on. My naive thought is marking Map with volatile keyword. For instance,
@volatile var map = Map.empty[Path, MyObject]
otherwise to synchronize the check-then-action operation code block.
However I am not sure if that’s enough. In addition I prefer functional style so I would like to check if there exists better or correct way to do it.