是否有不同步的Java堆栈的替代品? [英] Is there a drop-in replacement for Java Stack that is not synchronized?

查看:264
本文介绍了是否有不同步的Java堆栈的替代品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Stack数据结构的大型代码库(由我写)。这是为了方便而使用,我正在使用它作为Stack有时或Vector / List其他时间。



经过性能审查,但是决定我们不想支付额外的同步安全。我现在需要用非同步的方式来替换这个结构(在代码中提到很多次)。



我很高兴发现Apache集合包括一个 ArrayStack ,它是正是我想要的(与Java堆栈相同但不同步)。然而,这并不具有现代Java 5代码(这是我使用的)的泛型。我不会将我的代码转换为Java 1.4



所以有什么其他Java 5兼容的替代Java堆栈或者我需要写我自己的?



更新:



/push方法。

解决方案

当您说符合Java 5 - ArrayDeque< T> t到达Java 6,但听起来像你以后(当然,使用 Deque< T> 接口)。您可以使用它作为一个堆栈,当你想要,或一个队列,这更合适...只需调用适当的方法,基本上。


I have a large codebase (written by me) that uses the Stack data structure. This was used for convenience and I am using it as Stack sometimes or Vector/List some other times.

After a performance review however it was decided that we do not want to pay extra for the synchronization safety. I need now to replace this structure with a non-synchronized one (and it is mentioned a lot of times in the code).

I was happy to discover that Apache collections includes an ArrayStack which is exactly what I want (same as Java stack but non-synchronized). However this does NOT have generics as modern Java 5 code (which is what I use). And I am not going to convert my code to look like Java 1.4

So is there any other Java 5 compliant drop-in replacement for Java Stack or do I need to write my own?

Update:

I used LinkedList with tuned "pop"/"push" methods.

解决方案

When you say "Java 5 compliant" - ArrayDeque<T> didn't arrive until Java 6, but sounds like what you're after (using the Deque<T> interface where appropriate, of course). You can use it as a stack when you want to, or a queue where that's more appropriate... just call the appropriate methods, basically.

这篇关于是否有不同步的Java堆栈的替代品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆