kenn3th
kenn3th

Reputation: 1275

How to create a synchronized version of Google Guava's TreeMultimap

Does anyone know how to create a thread safe instance of TreeMultimap with TreeMultimap.create()?

Upvotes: 10

Views: 8757

Answers (2)

Sean Patrick Floyd
Sean Patrick Floyd

Reputation: 299048

The Guava Multimaps class contains static methods for creating and decorating Multimaps, similar to what the Collections class in java.util provides for Collections and Maps.

In your case, you should use:

Multimaps.synchronizedSortedSetMultimap(TreeMultimap.create())

Upvotes: 21

Haoyu Chen
Haoyu Chen

Reputation: 1810

Similarly, if you need to get synchronized version of ListMultiMap, you could use:

Multimaps.synchronizedListMultimap(ArrayListMultimap.create());

Google Guava Official doc

Upvotes: 8

Related Questions