开发者

What data structure should I use for a simple synchronized LIFO?

What data structure should I use for a simple synchronized LIFO? I'm using Android Java 1.6. The problem with Java collections is that there are millions开发者_如何学JAVA of slightly different classes and interfaces.


What about standard Stack? It is synchronized.

UPDATE

According to javadoc, you should use implementation of Deque instead of Stack. E.g. LinkedBlockingDeque


Queues

The java.util.concurrent ConcurrentLinkedQueue class supplies an efficient scalable thread-safe non-blocking FIFO queue. Five implementations in java.util.concurrent support the extended BlockingQueue interface, that defines blocking versions of put and take: LinkedBlockingQueue, ArrayBlockingQueue, SynchronousQueue, PriorityBlockingQueue, and DelayQueue. The different classes cover the most common usage contexts for producer-consumer, messaging, parallel tasking, and related concurrent designs. The BlockingDeque interface extends BlockingQueue to support both FIFO and LIFO (stack-based) operations. Class LinkedBlockingDeque provides an implementation.

Quoted from API Docs for Package java.util.concurrent.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜