This is an automated email from the ASF dual-hosted git repository.
cshannon pushed a commit to branch activemq-6.2.x
in repository https://gitbox.apache.org/repos/asf/activemq.git
The following commit(s) were added to refs/heads/activemq-6.2.x by this push:
new edf11f656f Improve performance of IntSequenceGenerator (#2408) (#2421)
edf11f656f is described below
commit edf11f656fdecdc7c3fce9408670aa65730e0734
Author: Christopher L. Shannon <[email protected]>
AuthorDate: Thu Aug 6 09:40:33 2026 -0400
Improve performance of IntSequenceGenerator (#2408) (#2421)
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
(cherry picked from commit 9c3add11f743ed97b438f2b630a11644e6772443)
---
.../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