[jboss-cvs] JBossAS SVN: r78433 - trunk/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:22:53 EDT 2008
Author: galder.zamarreno at jboss.com
Date: 2008-09-11 11:22:53 -0400 (Thu, 11 Sep 2008)
New Revision: 78433
Modified:
trunk/server/src/main/org/jboss/tm/usertx/server/UserTransactionSessionImpl.java
Log:
[JBAS-5948] Fix synchronisation issues with tm, tpcFactory and activeTx map.
Modified: trunk/server/src/main/org/jboss/tm/usertx/server/UserTransactionSessionImpl.java
===================================================================
--- trunk/server/src/main/org/jboss/tm/usertx/server/UserTransactionSessionImpl.java 2008-09-11 15:15:58 UTC (rev 78432)
+++ trunk/server/src/main/org/jboss/tm/usertx/server/UserTransactionSessionImpl.java 2008-09-11 15:22:53 UTC (rev 78433)
@@ -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;
}
@@ -259,24 +258,27 @@
{
log.debug("Lost connection to UserTransaction client.");
- if (!activeTx.isEmpty())
- {
- 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())
+ synchronized (activeTx)
+ {
+ 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