[jboss-svn-commits] JBL Code SVN: r34697 - labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Aug 13 05:18:21 EDT 2010


Author: jhalliday
Date: 2010-08-13 05:18:20 -0400 (Fri, 13 Aug 2010)
New Revision: 34697

Modified:
   labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/Uid.java
Log:
Backport Uid.getValue concurrency improvement. JBTM-771


Modified: labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/Uid.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/Uid.java	2010-08-13 08:56:46 UTC (rev 34696)
+++ labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/Uid.java	2010-08-13 09:18:20 UTC (rev 34697)
@@ -45,6 +45,7 @@
 import java.lang.StringIndexOutOfBoundsException;
 import java.lang.NumberFormatException;
 import java.lang.CloneNotSupportedException;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import com.arjuna.ats.arjuna.logging.tsLogger;
 
@@ -581,15 +582,20 @@
 		}
 	}
 
-	private static final synchronized int getValue ()
+    private static final int MAX_SEQ_VALUE = 0x40000000; // 2^30, which is a bit conservative.
+
+	private static int getValue ()
 	{
-		if ((Uid.uidsCreated & 0xf0000000) > 0)
-		{
-			Uid.uidsCreated = 0;
-			Uid.initTime = (int) (System.currentTimeMillis() / 1000);
-		}
+        int value = 0;
+        do {
+            value = uidsCreated.getAndIncrement();
+            if(value == MAX_SEQ_VALUE) {
+                uidsCreated.set(0);
+                initTime = (int) (System.currentTimeMillis() / 1000);
+            }
+        } while(value >= MAX_SEQ_VALUE);
 
-		return Uid.uidsCreated++;
+        return value;
 	}
 
 	/*
@@ -662,31 +668,31 @@
 
 	// use ints rather than longs for interoperability with C++ version
 
-	private int hostAddr;
+	private volatile int hostAddr;
 
-	private int process;
+	private volatile int process;
 
-	private int sec;
+	private volatile int sec;
 
-	private int other;
+	private volatile int other;
 
-	private int _hashValue;
+	private volatile int _hashValue;
 
-	private boolean _valid;
+	private volatile boolean _valid;
+	
+	private static final AtomicInteger uidsCreated = new AtomicInteger();
 
-	private static int uidsCreated ;
+	private static volatile int initTime ;
 
-	private static int initTime ;
+	private static final char breakChar = ':';
 
-	private static char breakChar = ':';
+	private static final char fileBreakChar = '_';
 
-	private static char fileBreakChar = '_';
+	private static final Uid NIL_UID = new Uid("0:0:0:0") ;
 
-	private static Uid NIL_UID = new Uid("0:0:0:0") ;
-
-	private static Uid LAST_RESOURCE_UID = new Uid("0:0:0:1") ;
+	private static final Uid LAST_RESOURCE_UID = new Uid("0:0:0:1") ;
 	
-	private static Uid MAX_UID = new Uid("7fffffff:7fffffff:7fffffff:7fffffff") ;
+	private static final Uid MAX_UID = new Uid("7fffffff:7fffffff:7fffffff:7fffffff") ;
 	
-	private static Uid MIN_UID = new Uid("-80000000:-80000000:-80000000:-80000000") ;
+	private static final Uid MIN_UID = new Uid("-80000000:-80000000:-80000000:-80000000") ;
 }



More information about the jboss-svn-commits mailing list