[jboss-cvs] JBossAS SVN: r76877 - in branches/Branch_4_2/server/src/main/org/jboss/ejb: plugins and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Aug 10 23:08:30 EDT 2008


Author: jeff.zhang
Date: 2008-08-10 23:08:30 -0400 (Sun, 10 Aug 2008)
New Revision: 76877

Modified:
   branches/Branch_4_2/server/src/main/org/jboss/ejb/EnterpriseContext.java
   branches/Branch_4_2/server/src/main/org/jboss/ejb/plugins/StatefulSessionInstanceInterceptor.java
Log:
[JBAS-4382] EnterpriseContext lock counting is not synchronized

Modified: branches/Branch_4_2/server/src/main/org/jboss/ejb/EnterpriseContext.java
===================================================================
--- branches/Branch_4_2/server/src/main/org/jboss/ejb/EnterpriseContext.java	2008-08-11 02:46:56 UTC (rev 76876)
+++ branches/Branch_4_2/server/src/main/org/jboss/ejb/EnterpriseContext.java	2008-08-11 03:08:30 UTC (rev 76877)
@@ -64,6 +64,8 @@
 import org.jboss.tm.TransactionTimeoutConfiguration;
 import org.jboss.tm.usertx.client.ServerVMClientUserTransaction;
 
+import EDU.oswego.cs.dl.util.concurrent.SynchronizedInt;
+
 //$Id$
 
 /**
@@ -132,7 +134,7 @@
    /**
     * The instance is being used.  This locks it's state
     */
-   int locked = 0;
+   volatile SynchronizedInt locked = new SynchronizedInt(0);
 
    /**
     * The instance is used in a transaction, synchronized methods on the tx
@@ -234,7 +236,7 @@
 
    public void lock()
    {
-      locked++;
+      locked.increment();
       //new Exception().printStackTrace();
       //DEBUG log.debug("EnterpriseContext.lock() "+hashCode()+" "+locked);
    }
@@ -243,10 +245,7 @@
    {
 
       // release a lock
-      locked--;
-
-      //new Exception().printStackTrace();
-      if (locked < 0)
+      if (locked.decrement() < 0)
       {
          // new Exception().printStackTrace();
          log.error("locked < 0", new Throwable());
@@ -259,7 +258,7 @@
    {
 
       //DEBUG log.debug("EnterpriseContext.isLocked() "+hashCode()+" at "+locked);
-      return locked != 0;
+      return locked.get() != 0;
    }
 
    public Principal getCallerPrincipal()
@@ -275,7 +274,7 @@
    public void clear()
    {
       this.id = null;
-      this.locked = 0;
+      this.locked.set(0);
       this.principal = null;
       this.beanPrincipal = null;
       this.synch = null;

Modified: branches/Branch_4_2/server/src/main/org/jboss/ejb/plugins/StatefulSessionInstanceInterceptor.java
===================================================================
--- branches/Branch_4_2/server/src/main/org/jboss/ejb/plugins/StatefulSessionInstanceInterceptor.java	2008-08-11 02:46:56 UTC (rev 76876)
+++ branches/Branch_4_2/server/src/main/org/jboss/ejb/plugins/StatefulSessionInstanceInterceptor.java	2008-08-11 03:08:30 UTC (rev 76877)
@@ -130,7 +130,12 @@
       mi.setEnterpriseContext(ctx);
       
       // It is a new context for sure so we can lock it
-      ctx.lock();
+      if (!ctx.isLocked())
+      {
+         
+         //take it!
+         ctx.lock();
+      }
       
       // Set the current security information
       ctx.setPrincipal(mi.getPrincipal());
@@ -497,7 +502,12 @@
             log.trace("beforeCompletion called");
 
          // lock the context the transaction is being commited (no need for sync)
-         ctx.lock();
+         if (!ctx.isLocked())
+         {
+            
+            //take it!
+            ctx.lock();
+         }
          beforeCompletionInvoked = true;
          
          if (notifySession)




More information about the jboss-cvs-commits mailing list