camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/3] camel git commit: CAMEL-11363: Optimise to use Dequeue instead of Stack. And no need for synchronization.
Date Wed, 31 May 2017 11:00:15 GMT
CAMEL-11363: Optimise to use Dequeue instead of Stack. And no need for synchronization.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/8b988f78
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8b988f78
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8b988f78

Branch: refs/heads/master
Commit: 8b988f78545bee9e16f397444146ef2dd8bc0a4a
Parents: 3478571
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Wed May 31 11:51:40 2017 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Wed May 31 13:00:05 2017 +0200

----------------------------------------------------------------------
 .../apache/camel/impl/DefaultUnitOfWork.java    | 30 +++++++-------------
 1 file changed, 11 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/8b988f78/camel-core/src/main/java/org/apache/camel/impl/DefaultUnitOfWork.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultUnitOfWork.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultUnitOfWork.java
index 14d379c..5baf0ee 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultUnitOfWork.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultUnitOfWork.java
@@ -16,11 +16,14 @@
  */
 package org.apache.camel.impl;
 
+import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.Deque;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.NoSuchElementException;
 import java.util.Set;
 import java.util.Stack;
 import java.util.function.Predicate;
@@ -65,7 +68,7 @@ public class DefaultUnitOfWork implements UnitOfWork, Service {
     private Message originalInMessage;
     private TracedRouteNodes tracedRouteNodes;
     private Set<Object> transactedBy;
-    private final Stack<RouteContext> routeContextStack = new Stack<RouteContext>();
+    private final Deque<RouteContext> routeContextStack = new ArrayDeque<>();
     private Stack<DefaultSubUnitOfWork> subUnitOfWorks;
     private final transient Logger log;
     
@@ -174,11 +177,7 @@ public class DefaultUnitOfWork implements UnitOfWork, Service {
         if (transactedBy != null) {
             transactedBy.clear();
         }
-        synchronized (routeContextStack) {
-            if (!routeContextStack.isEmpty()) {
-                routeContextStack.clear();
-            }
-        }
+        routeContextStack.clear();
         if (subUnitOfWorks != null) {
             subUnitOfWorks.clear();
         }
@@ -324,27 +323,20 @@ public class DefaultUnitOfWork implements UnitOfWork, Service {
     }
 
     public RouteContext getRouteContext() {
-        synchronized (routeContextStack) {
-            if (routeContextStack.isEmpty()) {
-                return null;
-            }
-            return routeContextStack.peek();
-        }
+        return routeContextStack.peek();
     }
 
     public void pushRouteContext(RouteContext routeContext) {
-        synchronized (routeContextStack) {
-            routeContextStack.add(routeContext);
-        }
+        routeContextStack.push(routeContext);
     }
 
     public RouteContext popRouteContext() {
-        synchronized (routeContextStack) {
-            if (routeContextStack.isEmpty()) {
-                return null;
-            }
+        try {
             return routeContextStack.pop();
+        } catch (NoSuchElementException e) {
+            // ignore and return null
         }
+        return null;
     }
 
     public AsyncCallback beforeProcess(Processor processor, Exchange exchange, AsyncCallback
callback) {


Mime
View raw message