db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1503157 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/xact/XactFactory.java
Date Mon, 15 Jul 2013 09:54:17 GMT
Author: kahatlen
Date: Mon Jul 15 09:54:16 2013
New Revision: 1503157

URL: http://svn.apache.org/r1503157
Log:
DERBY-4478: Use AtomicLong for XactFactory.tranId

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/xact/XactFactory.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/xact/XactFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/xact/XactFactory.java?rev=1503157&r1=1503156&r2=1503157&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/xact/XactFactory.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/xact/XactFactory.java
Mon Jul 15 09:54:16 2013
@@ -61,6 +61,7 @@ import org.apache.derby.iapi.error.Stand
 import org.apache.derby.iapi.util.InterruptStatus;
 
 import java.util.Properties;
+import java.util.concurrent.atomic.AtomicLong;
 
 public class XactFactory implements TransactionFactory, ModuleControl, ModuleSupportable
 {
@@ -87,7 +88,8 @@ public class XactFactory implements Tran
 	protected RawStoreFactory       rawStoreFactory;
 
 	public TransactionTable ttab;
-	private long	tranId;
+    /** The id of the next transaction to be started. */
+    private final AtomicLong tranId = new AtomicLong();
 	private LockingPolicy[][] lockingPolicies = new LockingPolicy[3][6];
 
 	private boolean inCreateNoLog = false;	// creating database, no logging
@@ -692,16 +694,12 @@ public class XactFactory implements Tran
 
 	public void setNewTransactionId(TransactionId oldxid, Xact t)
 	{
-		XactId xid;
 		boolean excludeMe = true; // by default
 
 		if (oldxid != null)
 			excludeMe = remove(oldxid);
 
-		synchronized(this)
-		{
-			xid = new XactId(tranId++);
-		}
+        XactId xid = new XactId(tranId.getAndIncrement());
 
 		t.setTransactionId(t.getGlobalId(), xid);
 
@@ -725,10 +723,8 @@ public class XactFactory implements Tran
 	public void resetTranId()
 	{
 		XactId xid = (XactId)ttab.largestUpdateXactId();
-		if (xid != null)
-			tranId = xid.getId() + 1;
-		else
-			tranId = 1;
+        long highestId = (xid == null) ? 0L : xid.getId();
+        tranId.set(highestId + 1);
 	}
 
 



Mime
View raw message