[英]How to achieve a thread-safe or immutable collection in fastutils?
Fastutil seems to be the fastest option for collections in Java. Fastutil 似乎是 Java 中集合的最快选择。
There are these javadocs: http:\/\/fastutil.di.unimi.it\/docs\/it\/unimi\/dsi\/fastutil\/longs\/Long2ObjectMaps.SynchronizedMap.html<\/a>有这些javadocs:http: \/\/fastutil.di.unimi.it\/docs\/it\/unimi\/dsi\/fastutil\/longs\/Long2ObjectMaps.SynchronizedMap.html<\/a>
but I have difficulty to find the usage example.但我很难找到用法示例。
How can I have a synchronized (thread-safe?) map?我怎样才能有一个同步的(线程安全的?)映射? An immutable map?不可变的地图?
" Each map type has its own synchronized wrapper class (eg Long2ObjectMaps.SynchronizedMap
as you linked above). 每种映射类型都有自己的同步包装类(例如,上面链接的Long2ObjectMaps.SynchronizedMap
)。 To use it, instantiate a concrete map implementation, then use the corresponding …Maps.synchronize()
method to get the synchronized version: 要使用它,请实例化具体的地图实现,然后使用相应的…Maps.synchronize()
方法获取同步版本:
Long2ObjectMap<Foo> unsynched = new Long2ObjectOpenHashMap<>();
// this is actually a Long2ObjectMaps.SynchronizedMap
Long2ObjectMap<Foo> synched = Long2ObjectMaps.synchronize(unsynchronized);
There is a lightweight thread-safe alternative: FastUtil Concurrent Wrapper<\/a> .有一个轻量级的线程安全替代方案: FastUtil Concurrent Wrapper<\/a> 。
"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.