This is an automated email from the ASF dual-hosted git repository.

cshannon pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq.git


The following commit(s) were added to refs/heads/main by this push:
     new 9c3add11f7 Improve performance of IntSequenceGenerator (#2408)
9c3add11f7 is described below

commit 9c3add11f743ed97b438f2b630a11644e6772443
Author: Christopher L. Shannon <[email protected]>
AuthorDate: Thu Aug 6 09:02:50 2026 -0400

    Improve performance of IntSequenceGenerator (#2408)
    
    This adopts the same approach as LongSequenceGenerator and uses an
    Atomic field updater to avoid using synchronized.
    
    The sequence generator is used by ResponseCorrelator so the existing
    tests will catch any errors.
    
    See https://issues.apache.org/jira/browse/AMQ-7300
---
 .../org/apache/activemq/util/IntSequenceGenerator.java  | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git 
a/activemq-client/src/main/java/org/apache/activemq/util/IntSequenceGenerator.java
 
b/activemq-client/src/main/java/org/apache/activemq/util/IntSequenceGenerator.java
index cbfbff72fd..fe3c7bc246 100644
--- 
a/activemq-client/src/main/java/org/apache/activemq/util/IntSequenceGenerator.java
+++ 
b/activemq-client/src/main/java/org/apache/activemq/util/IntSequenceGenerator.java
@@ -16,19 +16,24 @@
  */
 package org.apache.activemq.util;
 
+import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
+
 public class IntSequenceGenerator {
 
-    private int lastSequenceId;
+    private static final AtomicIntegerFieldUpdater<IntSequenceGenerator> 
SEQUENCE_UPDATER =
+            AtomicIntegerFieldUpdater.newUpdater(IntSequenceGenerator.class, 
"lastSequenceId");
+
+    private volatile int lastSequenceId;
 
-    public synchronized int getNextSequenceId() {
-        return ++lastSequenceId;
+    public int getNextSequenceId() {
+        return SEQUENCE_UPDATER.incrementAndGet(this);
     }
 
-    public synchronized int getLastSequenceId() {
+    public int getLastSequenceId() {
         return lastSequenceId;
     }
 
-    public synchronized void setLastSequenceId(int l) {
-        lastSequenceId = l;
+    public void setLastSequenceId(int l) {
+        SEQUENCE_UPDATER.set(this, l);
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to