User: osh
Date: 00/10/02 21:10:16
Modified: src/main/org/jboss/tm TxManager.java
Log:
Fixed a race where two threads would try to reuse the same TxCapsule instance
Revision Changes Path
1.19 +16 -9 jboss/src/main/org/jboss/tm/TxManager.java
Index: TxManager.java
===================================================================
RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/tm/TxManager.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- TxManager.java 2000/09/28 21:10:11 1.18
+++ TxManager.java 2000/10/03 04:10:15 1.19
@@ -12,6 +12,7 @@
import java.util.LinkedList;
import java.util.Map;
import java.util.HashMap;
+import java.util.Collections;
import javax.transaction.Status;
import javax.transaction.TransactionManager;
@@ -37,7 +38,7 @@
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Ole Husgaard</a>
- * @version $Revision: 1.18 $
+ * @version $Revision: 1.19 $
*/
public class TxManager
implements TransactionManager
@@ -70,16 +71,18 @@
"cannot nest transactions.");
TxCapsule txCapsule = null;
- while (inactiveCapsules.size() > 0) {
- SoftReference ref = (SoftReference)inactiveCapsules.removeFirst();
- txCapsule = (TxCapsule)ref.get();
- if (txCapsule != null) {
- txCapsule.reUse(timeOut);
- break;
+ synchronized (inactiveCapsules) {
+ while (inactiveCapsules.size() > 0) {
+ SoftReference ref = (SoftReference)inactiveCapsules.removeFirst();
+ txCapsule = (TxCapsule)ref.get();
+ if (txCapsule != null)
+ break;
}
}
if (txCapsule == null)
txCapsule = new TxCapsule(this, timeOut);
+ else
+ txCapsule.reUse(timeOut);
TransactionImpl tx = txCapsule.createTransactionImpl();
threadTx.set(tx);
activeCapsules.put(tx.xid, txCapsule);
@@ -265,7 +268,11 @@
void releaseTxCapsule(TxCapsule txCapsule)
{
activeCapsules.remove(txCapsule);
- inactiveCapsules.add(new SoftReference(txCapsule));
+
+ SoftReference ref = new SoftReference(txCapsule);
+ synchronized (inactiveCapsules) {
+ inactiveCapsules.add(ref);
+ }
}
@@ -283,7 +290,7 @@
* This map contains the active txCapsules as values.
* The keys are the <code>Xid</code> of the txCapsules.
*/
- private Map activeCapsules = new HashMap();
+ private Map activeCapsules = Collections.synchronizedMap(new HashMap());
/**
* This collection contains the inactive txCapsules.