This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 7b52e992b24 (chores) camel-main: use a LongAdder to reduce contention
(#11184)
7b52e992b24 is described below
commit 7b52e992b24087c5070c3093112077881eb036b3
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Wed Aug 23 14:23:05 2023 +0200
(chores) camel-main: use a LongAdder to reduce contention (#11184)
---
.../org/apache/camel/main/MainDurationEventNotifier.java | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git
a/core/camel-main/src/main/java/org/apache/camel/main/MainDurationEventNotifier.java
b/core/camel-main/src/main/java/org/apache/camel/main/MainDurationEventNotifier.java
index 7b6c6e52b31..17fd88f0508 100644
---
a/core/camel-main/src/main/java/org/apache/camel/main/MainDurationEventNotifier.java
+++
b/core/camel-main/src/main/java/org/apache/camel/main/MainDurationEventNotifier.java
@@ -19,7 +19,7 @@ package org.apache.camel.main;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.LongAdder;
import org.apache.camel.CamelContext;
import org.apache.camel.spi.CamelEvent;
@@ -42,8 +42,7 @@ public class MainDurationEventNotifier extends
EventNotifierSupport {
private final boolean stopCamelContext;
private final boolean restartDuration;
private final String action;
- private final AtomicInteger doneMessages;
-
+ private final LongAdder doneMessages;
private volatile StopWatch watch;
private volatile ScheduledExecutorService idleExecutorService;
@@ -57,7 +56,7 @@ public class MainDurationEventNotifier extends
EventNotifierSupport {
this.stopCamelContext = stopCamelContext;
this.restartDuration = restartDuration;
this.action = action.toLowerCase();
- this.doneMessages = new AtomicInteger();
+ this.doneMessages = new LongAdder();
if (maxMessages == 0 && maxIdleSeconds == 0) {
// we do not need exchange events
@@ -86,7 +85,7 @@ public class MainDurationEventNotifier extends
EventNotifierSupport {
if (restartDuration) {
LOG.debug("Routes reloaded. Resetting
maxMessages/maxIdleSeconds/maxSeconds");
shutdownStrategy.restartAwait();
- doneMessages.set(0);
+ doneMessages.reset();
if (watch != null) {
watch.restart();
}
@@ -100,9 +99,12 @@ public class MainDurationEventNotifier extends
EventNotifierSupport {
|| event.getType() == CamelEvent.Type.ExchangeFailed;
if (complete) {
- boolean result = doneMessages.incrementAndGet() >= maxMessages;
+ doneMessages.increment();
+ final int doneCount = doneMessages.intValue();
+ final boolean result = doneCount >= maxMessages;
+
if (LOG.isTraceEnabled()) {
- LOG.trace("Duration max messages check {} >= {} -> {}",
doneMessages.get(), maxMessages, result);
+ LOG.trace("Duration max messages check {} >= {} -> {}",
doneCount, maxMessages, result);
}
if (result && shutdownStrategy.isRunAllowed()) {