You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/05/26 12:38:30 UTC
camel git commit: CAMEL-11342: Optimise ManagedRoute to avoid
synchronized block when updating inflight oldest duration statistic
Repository: camel
Updated Branches:
refs/heads/CAMEL-11342 [created] b28ea66e6
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/b28ea66e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b28ea66e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b28ea66e
Branch: refs/heads/CAMEL-11342
Commit: b28ea66e6f4b6f967bf412f916e973bbe6b2f6e0
Parents: cbf469e
Author: Claus Ibsen <da...@apache.org>
Authored: Fri May 26 14:29:23 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri May 26 14:29:23 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/b28ea66e/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);
}