This is an automated email from the ASF dual-hosted git repository. juanpablo pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/jspwiki.git
commit 1e92176c6f4a62b32d5ed40a04f5401289747a80 Author: juanpablo <[email protected]> AuthorDate: Sun May 3 22:02:15 2020 +0200 replace synchronized int nextId() with AtomicInteger --- .../java/org/apache/wiki/workflow/DecisionQueue.java | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/jspwiki-main/src/main/java/org/apache/wiki/workflow/DecisionQueue.java b/jspwiki-main/src/main/java/org/apache/wiki/workflow/DecisionQueue.java index 679d714..a3fc33e 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/workflow/DecisionQueue.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/workflow/DecisionQueue.java @@ -28,6 +28,8 @@ import java.security.Principal; import java.util.ArrayList; import java.util.Collection; import java.util.LinkedList; +import java.util.concurrent.atomic.AtomicInteger; + /** * Keeps a queue of pending Decisions that need to be acted on by named Principals. @@ -40,11 +42,10 @@ public class DecisionQueue implements Serializable { private final LinkedList< Decision > m_queue = new LinkedList<>(); - private volatile int m_next; + private final AtomicInteger next = new AtomicInteger( 1_000 ); /** Constructs a new DecisionQueue. */ public DecisionQueue() { - m_next = 1000; } /** @@ -54,7 +55,7 @@ public class DecisionQueue implements Serializable { */ protected synchronized void add( final Decision decision ) { m_queue.addLast( decision ); - decision.setId( nextId() ); + decision.setId( next.getAndIncrement() ); } /** @@ -141,15 +142,4 @@ public class DecisionQueue implements Serializable { throw new IllegalStateException( "Reassignments not allowed for this decision." ); } - /** - * Returns the next available unique identifier, which is subsequently incremented. - * - * @return the id - */ - private synchronized int nextId() { - final int current = m_next; - m_next++; - return current; - } - }
