有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java FifoBuffer apache common collections 4替换

我想升级到apache。平民collections4,但是一些类CircularFifoBufferUnboundedFifoBuffer被删除

import org.apache.commons.collections.buffer.CircularFifoBuffer;

这些类的正确替代品是什么

找到几个suggestions

hadJan Haderka

Or perhaps there's yet another option:

replace buffer with MinMaxPriorityQueue which on it's own is also not thread safe, but guava fortunately provides wrapper for thread safety in form of Queues.synchronizedQueue(Queue q) call. Since we use guava elsewhere already it should be ok to use the library instead of commons. Not sure about performance comparison of the two tho.

Cedric Reichenbach

it seems like Queues#synchronizedQueue is indeed the equivalent of BufferUtils#synchronizedBuffer, i.e. synchronizes every access to the contained queue/buffer. However, a more precise match in Guava for CircularFifoBuffer would probably be EvictingQueue, or, since the sync wrapper works for any Queue, even Java's own Apache's new CircularFifoQueue.

我在{a2}或{a3}中没有找到答案


共 (1) 个答案

  1. # 1 楼答案

    在任务COLLECTIONS-432 Replace Buffer interface with java.util.Queue中找到答案

    BoundedFifoBuffer is replaced with java.util.concurrent.ArrayBlockingQueue

    CircularFifoBuffer is replaced with java.util.concurrent.ArrayBlockingQueue.

    PredicatedBuffer transfered into PredivatedBuffer

    PriorityBuffer is replaced with java.util.PriorityQueue

    SynchronizedBuffer is replaced with java.util.concurrent.SynchronizedQueue

    BlockingBuffer is replaced with java.util.concurrent.BlockingQueue (practical java.util.concurrent.ArrayBlockingQueue or java.util.concurrent.SynchronizedQueue)

    BoundedBuffer is replaced with java.util.concurrent.ArrayBlockingQueue

    TransformedBuffer transfered into TransformedQueue

    UnboundedFifoBuffer is replaced with java.util.concurrent.ArrayBlockingQueue