[concurrency-interest] Concurrent Bounded Stack

Zhong Yu zhong.j.yu at gmail.com
Sun May 27 11:20:12 EDT 2012


it is cool - but, is it really faster than java.util.Stack? by how much?

On Sat, May 26, 2012 at 4:42 PM, bestsss <stanimir at riflexo.com> wrote:
>
> Hi all,
> I suppose the issue might have popped multiple times, yet I have not seen it
> anywhere.
>
> Stacks are great for object pools but the only available in JDK are either:
> based on Vector or not thread safe (ArrayDeque), or don't have good size()
> method (ConcurrentLinkedDeque). JSR codebase has a dead ConcurrentStack on
> its own with slow size() method.
> Some projects like tomcat use CLQ for object pools, combined w/ an
> AtomicInteger for fast size() method. Neither queue make for proper pools,
> nor unsynchronized size() is a nice option.
>
> A few years back I thought that stacks can easily incorporate size on the
> top of the head by keeping it along  w/ the data element, thus having O(1)
> sync. size w/o any extra hurdle.
> Below is the code I've come up and it has been in production since. It makes
> a great pool for direct ByteBuffers and some other memory heavy structures.
> With proper sizing the hit ratio is usually over 99%.
>
>
> http://pastebin.com/GW1afBpz The Code at pastebin
>
> If you can share any possible problems with the implementation or the idea,
> itself, it'd be great. Also I am partly interested why such stack never made
> it into JSR166/JDK.
>
> Cheers
> Stanimir
>
> --
> View this message in context: http://old.nabble.com/Concurrent-Bounded-Stack-tp33913940p33913940.html
> Sent from the JSR166 Concurrency mailing list archive at Nabble.com.
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest



More information about the Concurrency-interest mailing list