Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

guava

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

like image 553
kenn3th Avatar asked Jul 28 '11 11:07

kenn3th


2 Answers

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())
like image 155
Sean Patrick Floyd Avatar answered Nov 08 '22 08:11

Sean Patrick Floyd


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

Multimaps.synchronizedListMultimap(ArrayListMultimap.create());

Google Guava Official doc

like image 8
Haoyu Chen Avatar answered Nov 08 '22 07:11

Haoyu Chen