Thread-safe Multiset

guava, java, multiset, multithreading, thread-safety

Solution

Use ConcurrentHashMultiset.

This bug report indicates that concurrent collections are preferred over synchronized wrappers, although that doesn't explain why `Multimaps.synchronizedMultimap` exists.

Problem

I have been googling for awhile and can't believe that I can't find it, but how can I safely implement a Multiset that will be accessed by multiple threads for both reading and writing. The multiset is storing views to certain pages, and will be a simple `Multiset<String>`. The older versions of Guava had a `synchronizedMultiset` function in the `Multisets` class. Should I just be using my own synchronized wrapper? I would prefer to use a library version if available.

Original source