You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jo...@apache.org on 2011/02/02 06:07:55 UTC

svn commit: r1066327 - /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java

Author: jonesde
Date: Wed Feb  2 05:07:54 2011
New Revision: 1066327

URL: http://svn.apache.org/viewvc?rev=1066327&view=rev
Log:
To avoid unnecessary synchronization for the fairly large number of calls that result in returning false instead of beginning a transaction moved the setTransactionTimeout and begin calls into a separate synchronized method and removed synchronized from the begin method

Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java?rev=1066327&r1=1066326&r2=1066327&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java Wed Feb  2 05:07:54 2011
@@ -136,14 +136,14 @@ public class TransactionUtil implements 
      * If and on only if it begins a transaction it will return true. In other words, if
      * a transaction is already in place it will return false and do nothing.
      */
-    public static synchronized boolean begin(int timeout) throws GenericTransactionException {
+    public static boolean begin(int timeout) throws GenericTransactionException {
         UserTransaction ut = TransactionFactory.getUserTransaction();
         if (ut != null) {
             try {
                 int currentStatus = ut.getStatus();
-                Debug.logVerbose("[TransactionUtil.begin] current status : " + getTransactionStateString(currentStatus), module);
+                if (Debug.verboseOn()) Debug.logVerbose("[TransactionUtil.begin] current status : " + getTransactionStateString(currentStatus), module);
                 if (currentStatus == Status.STATUS_ACTIVE) {
-                    Debug.logVerbose("[TransactionUtil.begin] active transaction in place, so no transaction begun", module);
+                    if (Debug.verboseOn()) Debug.logVerbose("[TransactionUtil.begin] active transaction in place, so no transaction begun", module);
                     return false;
                 } else if (currentStatus == Status.STATUS_MARKED_ROLLBACK) {
                     Exception e = getTransactionBeginStack();
@@ -162,20 +162,7 @@ public class TransactionUtil implements 
                     }
                 }
 
-                // set the timeout for THIS transaction
-                if (timeout > 0) {
-                    ut.setTransactionTimeout(timeout);
-                    Debug.logVerbose("[TransactionUtil.begin] set transaction timeout to : " + timeout + " seconds", module);
-                }
-
-                // begin the transaction
-                ut.begin();
-                Debug.logVerbose("[TransactionUtil.begin] transaction begun", module);
-
-                // reset the timeout to the default
-                if (timeout > 0) {
-                    ut.setTransactionTimeout(0);
-                }
+                internalBegin(ut, timeout);
 
                 // reset the transaction stamps, just in case...
                 clearTransactionStamps();
@@ -203,11 +190,28 @@ public class TransactionUtil implements 
                 throw new GenericTransactionException("System error, could not begin transaction", e);
             }
         } else {
-            Debug.logInfo("[TransactionUtil.begin] no user transaction, so no transaction begun", module);
+            if (Debug.infoOn()) Debug.logInfo("[TransactionUtil.begin] no user transaction, so no transaction begun", module);
             return false;
         }
     }
 
+    protected static synchronized void internalBegin(UserTransaction ut, int timeout) throws SystemException, NotSupportedException {
+        // set the timeout for THIS transaction
+        if (timeout > 0) {
+            ut.setTransactionTimeout(timeout);
+            if (Debug.verboseOn()) Debug.logVerbose("[TransactionUtil.begin] set transaction timeout to : " + timeout + " seconds", module);
+        }
+
+        // begin the transaction
+        ut.begin();
+        if (Debug.verboseOn()) Debug.logVerbose("[TransactionUtil.begin] transaction begun", module);
+
+        // reset the timeout to the default
+        if (timeout > 0) {
+            ut.setTransactionTimeout(0);
+        }
+    }
+
     /** Gets the status of the transaction in the current thread IF
      * transactions are available, otherwise returns STATUS_NO_TRANSACTION */
     public static int getStatus() throws GenericTransactionException {