开发者

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

开发者 https://www.devze.com 2023-04-10 11:38 出处:网络
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 classe

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

精彩评论

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

关注公众号