Just because I was curious, how did you test this or how are you using it?  
Developers of Java are pretty convinced that ArrayDeque is faster than a Stack 
in most situations.

Snippet from the java doc for ArrayDeque:

      This class is likely to be faster than
* {@link Stack} when used as a stack, and faster than {@link LinkedList}
* when used as a queue.
 *
* <p>Most <tt>ArrayDeque</tt> operations run in amortized constant time.
* Exceptions include {@link #remove(Object) remove}, {@link
* #removeFirstOccurrence removeFirstOccurrence}, {@link #removeLastOccurrence
* removeLastOccurrence}, {@link #contains contains}, {@link #iterator
* iterator.remove()}, and the bulk operations, all of which run in linear
* time.

Hope this helps!

Thanks,
Kurt

From: Ralph Goers [mailto:[email protected]]
Sent: Friday, May 16, 2014 11:07 AM
To: Log4J Developers List
Subject: Re: svn commit: r1593125 - in 
/logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j: 
ThreadContext.java spi/ThreadContextStack.java

Believe it or not, when I tested ArrayDeque I found that it was slower than 
Stack.

Ralph

On May 16, 2014, at 7:33 AM, Gary Gregory 
<[email protected]<mailto:[email protected]>> wrote:


It's also hard to think of a "stack" as _not_ being a "collection".
This is a good time to talk about it since we'll be stuck with it when we ship 
2.0.
Also I could understand why we would not want a java.util.Stack since it is a 
Vector, but Java offers ArrayDeque. So why not use that?
Gary

On Fri, May 16, 2014 at 10:29 AM, Gary Gregory 
<[email protected]<mailto:[email protected]>> wrote:
All of the ThreadContextStack implementations we have are Collections though... 
(that was the case before the refactoring)
Gary

On Thu, May 15, 2014 at 11:19 AM, Ralph Goers 
<[email protected]<mailto:[email protected]>> wrote:
I actually dislike ThreadContextStack but it is there for compatibility with 
Log4j 1.x.  I guess there are people who use it.  I didn't make it a Collection 
in the first place for the exact reasons you mention - they aren't used.

Ralph

On May 14, 2014, at 9:24 PM, Remko Popma 
<[email protected]<mailto:[email protected]>> wrote:

> Well, the difference is that now the api (the ThreadContext.ContextStack 
> interface) extends Collection, so all implementations now *must* support all 
> methods declared on Collection. This was not a requirement before.
> (Not sure why spi.ThreadContextStack extends Collection, by the way. 
> ThreadContext will not use these methods...)
>
> Remko
>
> Sent from my iPhone
>
>> On 2014/05/08, at 4:35, [email protected]<mailto:[email protected]> 
>> wrote:
>>
>> Author: ggregory
>> Date: Wed May  7 19:35:45 2014
>> New Revision: 1593125
>>
>> URL: http://svn.apache.org/r1593125
>> Log:
>> ThreadContext.ContextStack is already (conceptually) a collection of Strings 
>> so it should be a Collection<String> instead of it's sub-interface 
>> ThreadContextStack being a Collection<String>. What's the value of 
>> ThreadContextStack now? Should we keep it as a placeholder? It is not 
>> documented in its Javadoc. Note that all implementations of ContextStack are 
>> implementations of ThreadContextStack, so this change has no effect on 
>> implementors. Note that Log4jLogEvent holds a ContextStack so this makes it 
>> a Collection<String> which happens to save a lot of work for XML and JSON IO 
>> for the Jackson based receivers and layouts I am working on.
>>
>> Modified:
>>   
>> logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/ThreadContext.java
>>   
>> logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/spi/ThreadContextStack.java
>>
>> Modified: 
>> logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/ThreadContext.java
>> URL: 
>> http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/ThreadContext.java?rev=1593125&r1=1593124&r2=1593125&view=diff
>> ==============================================================================
>> --- 
>> logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/ThreadContext.java
>>  (original)
>> +++ 
>> logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/ThreadContext.java
>>  Wed May  7 19:35:45 2014
>> @@ -347,12 +347,7 @@ public final class ThreadContext  {
>>    /**
>>     * The ThreadContext Stack interface.
>>     */
>> -    public interface ContextStack extends Serializable {
>> -
>> -        /**
>> -         * Clears all elements from the stack.
>> -         */
>> -        void clear();
>> +    public interface ContextStack extends Serializable, Collection<String> {
>>
>>        /**
>>         * Returns the element at the top of the stack.
>>
>> Modified: 
>> logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/spi/ThreadContextStack.java
>> URL: 
>> http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/spi/ThreadContextStack.java?rev=1593125&r1=1593124&r2=1593125&view=diff
>> ==============================================================================
>> --- 
>> logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/spi/ThreadContextStack.java
>>  (original)
>> +++ 
>> logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/spi/ThreadContextStack.java
>>  Wed May  7 19:35:45 2014
>> @@ -16,12 +16,10 @@
>> */
>> package org.apache.logging.log4j.spi;
>>
>> -import java.util.Collection;
>> -
>> import org.apache.logging.log4j.ThreadContext;
>>
>> /**
>> *
>> */
>> -public interface ThreadContextStack extends ThreadContext.ContextStack, 
>> Collection<String> {
>> +public interface ThreadContextStack extends ThreadContext.ContextStack {
>> }
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: 
> [email protected]<mailto:[email protected]>
> For additional commands, e-mail: 
> [email protected]<mailto:[email protected]>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: 
[email protected]<mailto:[email protected]>
For additional commands, e-mail: 
[email protected]<mailto:[email protected]>


--
E-Mail: [email protected]<mailto:[email protected]> | 
[email protected] <mailto:[email protected]>
Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition<http://www.manning.com/tahchiev/>
Spring Batch in Action<http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com<http://garygregory.wordpress.com/>
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory



--
E-Mail: [email protected]<mailto:[email protected]> | 
[email protected] <mailto:[email protected]>
Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition<http://www.manning.com/tahchiev/>
Spring Batch in Action<http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com<http://garygregory.wordpress.com/>
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Reply via email to