Skip to content

Commit

Permalink
Replaced Stack with Deque
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Koval committed Feb 19, 2018
1 parent e8f6e6d commit 4b17d30
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Expand Up @@ -19,12 +19,13 @@
*/ */
package org.neo4j.kernel.impl.locking.community; package org.neo4j.kernel.impl.locking.community;


import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Stack;


import org.neo4j.kernel.DeadlockDetectedException; import org.neo4j.kernel.DeadlockDetectedException;
import org.neo4j.kernel.impl.util.ArrayMap; import org.neo4j.kernel.impl.util.ArrayMap;
Expand Down Expand Up @@ -132,7 +133,7 @@ synchronized void checkWaitOn( Object resource, Object tx )


Iterator<Object> itr = lockingTxList.iterator(); Iterator<Object> itr = lockingTxList.iterator();
List<Object> checkedTransactions = new LinkedList<>(); List<Object> checkedTransactions = new LinkedList<>();
Stack<Object> graphStack = new Stack<>(); final Deque<Object> graphStack = new ArrayDeque<>();
// has resource,transaction interleaved // has resource,transaction interleaved
graphStack.push( resource ); graphStack.push( resource );
while ( itr.hasNext() ) while ( itr.hasNext() )
Expand Down Expand Up @@ -162,8 +163,7 @@ synchronized void checkWaitOn( Object resource, Object tx )
continue; continue;
} }
graphStack.push( lockingTx ); graphStack.push( lockingTx );
checkWaitOnRecursive( lockingTx, tx, checkedTransactions, checkWaitOnRecursive( lockingTx, tx, checkedTransactions, graphStack );
graphStack );
graphStack.pop(); graphStack.pop();
} }


Expand All @@ -173,7 +173,7 @@ synchronized void checkWaitOn( Object resource, Object tx )


private synchronized void checkWaitOnRecursive( Object lockingTx, private synchronized void checkWaitOnRecursive( Object lockingTx,
Object waitingTx, List<Object> checkedTransactions, Object waitingTx, List<Object> checkedTransactions,
Stack<Object> graphStack ) throws DeadlockDetectedException Deque<Object> graphStack ) throws DeadlockDetectedException
{ {
if ( lockingTx.equals( waitingTx ) ) if ( lockingTx.equals( waitingTx ) )
{ {
Expand Down
Expand Up @@ -19,13 +19,14 @@
*/ */
package org.neo4j.causalclustering.core.replication.session; package org.neo4j.causalclustering.core.replication.session;


import java.util.ArrayDeque;
import java.util.Deque;
import java.util.EmptyStackException; import java.util.EmptyStackException;
import java.util.Stack;


/** Keeps a pool of local sub-sessions, to be used under a single global session. */ /** Keeps a pool of local sub-sessions, to be used under a single global session. */
public class LocalSessionPool public class LocalSessionPool
{ {
private final Stack<LocalSession> sessionStack = new Stack<>(); private final Deque<LocalSession> sessionStack = new ArrayDeque<>();


private final GlobalSession globalSession; private final GlobalSession globalSession;
private long nextLocalSessionId; private long nextLocalSessionId;
Expand Down

0 comments on commit 4b17d30

Please sign in to comment.