[jboss-cvs] JBossAS SVN: r78429 - branches/JBPAPP_4_2_0_GA_CP/server/src/main/org/jboss/tm/usertx/server.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Sep 11 11:11:36 EDT 2008


Author: galder.zamarreno at jboss.com
Date: 2008-09-11 11:11:36 -0400 (Thu, 11 Sep 2008)
New Revision: 78429

Modified:
   branches/JBPAPP_4_2_0_GA_CP/server/src/main/org/jboss/tm/usertx/server/UserTransactionSessionImpl.java
Log:
[JBPAPP-1175] Fix synchronisation issues with tm, tpcFactory and activeTx map.

Modified: branches/JBPAPP_4_2_0_GA_CP/server/src/main/org/jboss/tm/usertx/server/UserTransactionSessionImpl.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/server/src/main/org/jboss/tm/usertx/server/UserTransactionSessionImpl.java	2008-09-11 14:37:20 UTC (rev 78428)
+++ branches/JBPAPP_4_2_0_GA_CP/server/src/main/org/jboss/tm/usertx/server/UserTransactionSessionImpl.java	2008-09-11 15:11:36 UTC (rev 78429)
@@ -22,7 +22,9 @@
 package org.jboss.tm.usertx.server;
 
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Iterator;
+import java.util.Map;
 
 import java.rmi.RemoteException;
 
@@ -49,6 +51,7 @@
  *  It handles transactions on behalf of a single client.
  * @author Ole Husgaard
  * @author Scott.Stark at jboss.org
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
  * @version $Revision$
  */
 public class UserTransactionSessionImpl
@@ -60,7 +63,7 @@
    /**
     *  Maps the TPCs of all active transactions to their transactions.
     */
-   private static WeakValueHashMap activeTx = new WeakValueHashMap();
+   private static Map activeTx = Collections.synchronizedMap(new WeakValueHashMap());
    private static UserTransactionSessionImpl instance = new UserTransactionSessionImpl();
 
    public static UserTransactionSession getInstance()
@@ -71,7 +74,7 @@
    /**
     *  Get a reference to the transaction manager.
     */
-   protected static TransactionManager getTransactionManager()
+   protected synchronized static TransactionManager getTransactionManager()
    {
       if (tm == null)
       {
@@ -89,17 +92,13 @@
    }
 
    /** Cache a reference to the TPC Factory. */
-   private static TransactionPropagationContextFactory tpcFactory = null;
+   private static TransactionPropagationContextFactory tpcFactory = TransactionPropagationContextUtil.getTPCFactory();
    
    /**
     *  Get a reference to the TPC Factory
     */
    protected static TransactionPropagationContextFactory getTPCFactory()
    {
-      if (tpcFactory == null)
-      {
-         tpcFactory = TransactionPropagationContextUtil.getTPCFactory();
-      }
       return tpcFactory;
    }  
 
@@ -165,20 +164,16 @@
       TransactionManager tm = getTransactionManager();
       tm.resume(tx);
 
-      boolean finished = true;
-      
       try
       {
          tm.commit();
       }
       catch (java.lang.SecurityException ex)
       {
-         finished = false;
          throw ex;
       }
       catch (java.lang.IllegalStateException ex)
       {
-         finished = false;
          throw ex;
       }
       finally
@@ -259,24 +254,27 @@
    {
       log.debug("Lost connection to UserTransaction client.");
       
-      if (!activeTx.isEmpty())
+      synchronized (activeTx)
       {
-         log.error("Lost connection to UserTransaction clients: " +
-         "Rolling back " + activeTx.size() +
-         " active transaction(s).");
-         Collection txs = activeTx.values();
-         Iterator iter = txs.iterator();
-         while (iter.hasNext())
+         if (!activeTx.isEmpty())
          {
-            Transaction tx = (Transaction)iter.next();
-            try
+            log.error("Lost connection to UserTransaction clients: " +
+            "Rolling back " + activeTx.size() +
+            " active transaction(s).");
+            Collection txs = activeTx.values();
+            Iterator iter = txs.iterator();
+            while (iter.hasNext())
             {
-               tx.rollback();
+               Transaction tx = (Transaction)iter.next();
+               try
+               {
+                  tx.rollback();
+               }
+               catch (Exception ex)
+               {
+                  log.error("rollback failed", ex);
+               }
             }
-            catch (Exception ex)
-            {
-               log.error("rollback failed", ex);
-            }
          }
       }
    }




More information about the jboss-cvs-commits mailing list