camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [4/9] camel git commit: CAMEL-11342: Optimise ManagedRoute to avoid synchronized block when updating inflight oldest duration statistic
Date Sat, 27 May 2017 07:29:07 GMT
CAMEL-11342: Optimise ManagedRoute to avoid synchronized block when updating inflight oldest
duration statistic


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

Branch: refs/heads/master
Commit: bd105648adf2fa8121788619e8559a09515a196e
Parents: 140bdf1
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Fri May 26 14:29:23 2017 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat May 27 09:03:46 2017 +0200

----------------------------------------------------------------------
 .../camel/management/mbean/ManagedRoute.java    | 28 +++++++++-----------
 1 file changed, 13 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/bd105648/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
index b0fca83..166f3a2 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
@@ -491,32 +491,30 @@ public class ManagedRoute extends ManagedPerformanceCounter implements
TimerList
     }
 
     @Override
-    public synchronized void processExchange(Exchange exchange) {
-        InFlightKey key = new InFlightKey(System.currentTimeMillis(), exchange.getExchangeId());
-        InFlightKey oldKey = exchangesInFlightKeys.putIfAbsent(exchange.getExchangeId(),
key);
-        // we may already have the exchange being processed so only add to timestamp if its
a new exchange
-        // for example when people call the same routes recursive
-        if (oldKey == null) {
+    public void processExchange(Exchange exchange) {
+        exchangesInFlightKeys.computeIfAbsent(exchange.getExchangeId(), id -> {
+            InFlightKey key = new InFlightKey(System.currentTimeMillis(), exchange.getExchangeId());
             exchangesInFlightStartTimestamps.put(key, key.timeStamp);
-        }
+            return key;
+        });
         super.processExchange(exchange);
     }
 
     @Override
-    public synchronized void completedExchange(Exchange exchange, long time) {
-        InFlightKey key = exchangesInFlightKeys.remove(exchange.getExchangeId());
-        if (key != null) {
+    public void completedExchange(Exchange exchange, long time) {
+        exchangesInFlightKeys.computeIfPresent(exchange.getExchangeId(), (id, key) ->
{
             exchangesInFlightStartTimestamps.remove(key);
-        }
+            return null;
+        });
         super.completedExchange(exchange, time);
     }
 
     @Override
-    public synchronized void failedExchange(Exchange exchange) {
-        InFlightKey key = exchangesInFlightKeys.remove(exchange.getExchangeId());
-        if (key != null) {
+    public void failedExchange(Exchange exchange) {
+        exchangesInFlightKeys.computeIfPresent(exchange.getExchangeId(), (id, key) ->
{
             exchangesInFlightStartTimestamps.remove(key);
-        }
+            return null;
+        });
         super.failedExchange(exchange);
     }
 


Mime
View raw message