Since the lock on the map is released once Items() returns, the janitor can come along and concurrently modify the map while user code is accessing it. Adding a wrapper of synchronisation as suggested by the documentation is useless.
The solution is to explicitly copy the map and return the copy.
Since the lock on the map is released once Items() returns, the janitor can come along and concurrently modify the map while user code is accessing it. Adding a wrapper of synchronisation as suggested by the documentation is useless.
The solution is to explicitly copy the map and return the copy.