User: starksm 
  Date: 01/07/17 20:30:02

  Modified:    src/main/org/jboss/ejb/plugins Tag: Branch_2_2
                        EntityInstanceInterceptor.java
  Log:
  A simple workaround for the busy wait spin in the presence of tx contention
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.28.2.2  +14 -10    
jboss/src/main/org/jboss/ejb/plugins/EntityInstanceInterceptor.java
  
  Index: EntityInstanceInterceptor.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/EntityInstanceInterceptor.java,v
  retrieving revision 1.28.2.1
  retrieving revision 1.28.2.2
  diff -u -r1.28.2.1 -r1.28.2.2
  --- EntityInstanceInterceptor.java    2001/07/17 03:26:50     1.28.2.1
  +++ EntityInstanceInterceptor.java    2001/07/18 03:30:02     1.28.2.2
  @@ -45,10 +45,11 @@
    *   @author Rickard Öberg ([EMAIL PROTECTED])
    *   @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
    *   @author <a href="mailto:[EMAIL PROTECTED]";>Sebastien Alborini</a>
  - *   @version $Revision: 1.28.2.1 $
  + *   @author <a href="mailto:[EMAIL PROTECTED]";>Scott Stark</a>
  + *   @version $Revision: 1.28.2.2 $
    */
   public class EntityInstanceInterceptor
  -extends AbstractInterceptor
  +   extends AbstractInterceptor
   {
      // Constants -----------------------------------------------------
      
  @@ -72,7 +73,7 @@
      
      // Interceptor implementation --------------------------------------
      public Object invokeHome(MethodInvocation mi)
  -   throws Exception
  +      throws Exception
      {
         // Get context
         EnterpriseContext ctx = 
((EntityContainer)getContainer()).getInstancePool().get();
  @@ -99,7 +100,7 @@
      }
      
      public Object invoke(MethodInvocation mi)
  -   throws Exception
  +      throws Exception
      {
         // The id store is a CacheKey in the case of Entity
         CacheKey key = (CacheKey)mi.getId();
  @@ -112,6 +113,7 @@
         
         try
         {
  +         boolean waitingOnTransaction = false;
            do
            {
               if (mi.getTransaction() != null && mi.getTransaction().getStatus() == 
Status.STATUS_MARKED_ROLLBACK)
  @@ -119,7 +121,10 @@
               
               try
               {
  -               
  +               // Don't let contending thread spin on the cpu
  +               if( waitingOnTransaction == true )
  +                  Thread.sleep(1);
  +
                  mutex.acquire();
                  
                  // Get context
  @@ -133,17 +138,16 @@
                  {
                     // Let's put the thread to sleep a lock release will wake the 
thread
                     // Possible deadlock
  -                  Logger.debug("LOCKING-WAITING (TRANSACTION) for id 
"+ctx.getId()+" ctx.hash "+ctx.hashCode()+" tx:"+((tx == null) ? "null" : 
tx.toString()));
  -                  synchronized( tx )
  -                  {
  -                     tx.wait(1000);
  -                  }
  +                  if( waitingOnTransaction == false )
  +                     Logger.debug("LOCKING-WAITING (TRANSACTION) for id 
"+ctx.getId()+" ctx.hash "+ctx.hashCode()+" tx:"+((tx == null) ? "null" : 
tx.toString()));
  +                  waitingOnTransaction = true;
                     // Try your luck again
                     ctx = null;
                     continue;
                  }
                  else
                  {
  +                  waitingOnTransaction = false;
                     // If we get here it's the right tx, or no tx
                     if (!ctx.isLocked())
                     {
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to