User: fleury
Date: 00/09/26 15:37:15
Modified: src/main/org/jboss/ejb/plugins
EntityInstanceInterceptor.java
TxInterceptorBMT.java
Log:
Fixed ctx unlock problem in EntityInstanceInterceptor
Revision Changes Path
1.10 +53 -44
jboss/src/main/org/jboss/ejb/plugins/EntityInstanceInterceptor.java
Index: EntityInstanceInterceptor.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/EntityInstanceInterceptor.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- EntityInstanceInterceptor.java 2000/09/26 20:18:50 1.9
+++ EntityInstanceInterceptor.java 2000/09/26 22:37:15 1.10
@@ -42,7 +42,7 @@
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="[EMAIL PROTECTED]">Marc Fleury</a>
-* @version $Revision: 1.9 $
+* @version $Revision: 1.10 $
*/
public class EntityInstanceInterceptor
extends AbstractInterceptor
@@ -75,7 +75,7 @@
EnterpriseContext ctx =
((EntityContainer)getContainer()).getInstancePool().get();
mi.setEnterpriseContext(ctx);
- // It is a new context for sure so we can lock it (no need for sync
(not in cache))
+ // It is a new context for sure so we can lock it
ctx.lock();
try
@@ -84,12 +84,12 @@
return getNext().invokeHome(mi);
} finally
{
+ // Always unlock, no matter what
+ ctx.unlock();
+
// Still free? Not free if create() was called successfully
if (mi.getEnterpriseContext().getId() == null)
{
- // Free that context
- ctx.unlock();
-
container.getInstancePool().free(mi.getEnterpriseContext());
}
else
@@ -97,9 +97,6 @@
// DEBUG Logger.log("Entity was created; not
returned to pool");
synchronized (ctx) {
- // Release the lock
- ctx.unlock();
-
//Let the waiters know
ctx.notifyAll();
}
@@ -113,54 +110,66 @@
// The id store is a CacheKey in the case of Entity
CacheKey key = (CacheKey) mi.getId();
- // Get context
- EnterpriseContext ctx =
((EntityContainer)getContainer()).getInstanceCache().get(key);
+ // Get cache
+ InstanceCache cache =
((EntityContainer)getContainer()).getInstanceCache();
- // Set it on the method invocation
- mi.setEnterpriseContext(ctx);
+ EnterpriseContext ctx = null;
// We synchronize the locking logic (so that the invoke is
unsynchronized and can be reentrant)
- synchronized (ctx)
+ synchronized (cache)
{
- // Do we have a running transaction with the context
- if (ctx.getTransaction() != null &&
- // And are we trying to enter with another transaction
- !ctx.getTransaction().equals(mi.getTransaction()))
+ do
{
- // Let's put the thread to sleep a lock release will
wake the thread
- try{ctx.wait();}
- catch (InterruptedException ie) {}
+ // Get context
+ ctx = cache.get(key);
- // Try your luck again
- return invoke(mi);
- }
-
- if (!ctx.isLocked()){
-
- //take it!
- ctx.lock();
- }
-
- else
- {
- if (!isCallAllowed(mi)) {
-
+ // Do we have a running transaction with the context
+ if (ctx.getTransaction() != null &&
+ // And are we trying to enter with another
transaction
+
!ctx.getTransaction().equals(mi.getTransaction()))
+ {
// Let's put the thread to sleep a lock
release will wake the thread
- try{ctx.wait();}
- catch (InterruptedException ie) {}
+ synchronized (ctx)
+ {
+ try{ctx.wait();}
+ catch (InterruptedException
ie) {}
+ }
// Try your luck again
- return invoke(mi);
+ ctx = null;
+ continue;
}
- // The call is allowed, do increment the lock though
(ctx already locked)
- ctx.lock();
- }
-
- }
+ if (!ctx.isLocked()){
+
+ //take it!
+ ctx.lock();
+ }
+
+ else
+ {
+ if (!isCallAllowed(mi)) {
+
+ // Let's put the thread to sleep a
lock release will wake the thread
+ synchronized (ctx)
+ {
+ try{ctx.wait();}
+ catch
(InterruptedException ie) {}
+ }
+
+ // Try your luck again
+ ctx = null;
+ continue;
+ }
+ }
+
+ } while (ctx == null);
+ }
+
+ // Set context on the method invocation
+ mi.setEnterpriseContext(ctx);
try {
-
// Go on, you won
return getNext().invoke(mi);
@@ -200,7 +209,7 @@
if (ctx.getId() == null)
{
// Remove from cache
-
((EntityContainer)getContainer()).getInstanceCache().remove(key.id);
+ cache.remove(key.id);
// It has been removed -> send to free
pool
container.getInstancePool().free(ctx);
1.2 +13 -1 jboss/src/main/org/jboss/ejb/plugins/TxInterceptorBMT.java
Index: TxInterceptorBMT.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/TxInterceptorBMT.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TxInterceptorBMT.java 2000/09/26 17:30:19 1.1
+++ TxInterceptorBMT.java 2000/09/26 22:37:15 1.2
@@ -49,7 +49,7 @@
* @see <related>
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Sebastien Alborini</a>
-* @version $Revision: 1.1 $
+* @version $Revision: 1.2 $
*/
public class TxInterceptorBMT
extends AbstractInterceptor
@@ -109,6 +109,9 @@
// (mi has the sessioncontext from the previous interceptor)
if (((SessionMetaData)container.getBeanMetaData()).isStateful()) {
+ // Save old userTx
+ Object oldUserTx = userTransaction.get();
+
// retrieve the real userTransaction
userTransaction.set(((StatefulSessionEnterpriseContext)mi.getEnterpriseContext()).getSessionContext().getUserTransaction());
@@ -132,6 +135,9 @@
} finally {
+ // Reset user Tx
+ userTransaction.set(oldUserTx);
+
if (t1 != null) {
// reassociate the previous transaction before
returning
@@ -160,6 +166,9 @@
*/
public Object invoke(MethodInvocation mi) throws Exception {
+ // Store old UserTX
+ Object oldUserTx = userTransaction.get();
+
// set the threadlocal to the userTransaction of the instance
// (mi has the sessioncontext from the previous interceptor)
if (((SessionMetaData)container.getBeanMetaData()).isStateful()) {
@@ -199,6 +208,9 @@
return getNext().invoke(mi);
} finally {
+
+ // Reset user Tx
+ userTransaction.set(oldUserTx);
if (t1 != null) {