简体   繁体   中英

thread safe random access circular array in java?

I need to cache the least recent result (say 10,000) of a concurrent system, and random access them. Since most of concurrent cache are based on linked list, I'm wondering if there is a thread safe random access circular array in java?

For caches without timeout, I often use the ConcurrentHashMap . You may also take a look at the CopyOnWriteArrayList .

https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentHashMap.html https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CopyOnWriteArrayList.html

There is an implementation of CircularFifoQueue in the Apache Commons Collections library. It contains a get() method for random access. For a thread-safe version, you can wrap its instance with the SynchronizedQueue wrapper. Another solution is the cyclic ArrayList/Vector implementation, described in detail here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM