'Thread safe swap of entire map in Java

I'm implementing thread-safe map in the spring web service.

The map is such like this.

  • The map is read simultaneously in thousands of client threads.
  • The map's content has to be entirely updated sometimes(about once per hour).

I've chosen ConcurrentHashMap for thread-safe map, but there was no functionality to simply swap its content with newer one, like std::map::swap() in c++.
(I thought that atomic update of the entire content is required for multi-thread environment, maybe I'm wrong)

Is there an alternative map with swap?

Any suggestion or reply will be appreciated. Thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source