User: patriot1burke
  Date: 02/04/09 22:44:03

  Modified:    src/main/org/jboss/ejb/plugins/lock
                        QueuedPessimisticEJBLock.java
  Log:
  read-only methods and read-only beans will now release transactional locks at the
  end of an invocation.
  
  Revision  Changes    Path
  1.9       +31 -29    
jboss/src/main/org/jboss/ejb/plugins/lock/QueuedPessimisticEJBLock.java
  
  Index: QueuedPessimisticEJBLock.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/lock/QueuedPessimisticEJBLock.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- QueuedPessimisticEJBLock.java     12 Jan 2002 20:21:07 -0000      1.8
  +++ QueuedPessimisticEJBLock.java     10 Apr 2002 05:44:03 -0000      1.9
  @@ -14,7 +14,8 @@
   import javax.transaction.Status;
   
   import org.jboss.invocation.Invocation;
  -
  +import org.jboss.ejb.Container;
  +import org.jboss.ejb.EntityContainer;
   
   /**
    * This class is holds threads awaiting the transactional lock to be free
  @@ -30,19 +31,29 @@
    * When the reference count goes to 0, the lock is released from the
    * id -> lock mapping.
    *
  + * As of 04/10/2002, you can now specify in jboss.xml method attributes that define
  + * methods as read-only.  read-only methods(and read-only beans) will release 
transactional
  + * locks at the end of the invocation.  This decreases likelyhood of deadlock and 
increases
  + * performance.
  + *
    * FIXME marcf: we should get solid numbers on this locking, bench in multi-thread 
environments
    * We need someone with serious SUN hardware to run this lock into the ground
    *
    * @author <a href="[EMAIL PROTECTED]">Marc Fleury</a>
    * @author <a href="[EMAIL PROTECTED]">Bill Burke</a>
  + * @author <a href="[EMAIL PROTECTED]">Peter Murray</a>
    *
  - * @version $Revision: 1.8 $
  + * @version $Revision: 1.9 $
    *
    * <p><b>Revisions:</b><br>
    * <p><b>2001/08/03: billb</b>
    *  <ol>
    *  <li>Initial revision
    *  </ol>
  + * <p><b>2002/04/10: billb </b>
  + *  <ol>
  + *  <li>Applied Peter Murray's read-only locking mechanisms.
  + *  </ol>
    */
   public class QueuedPessimisticEJBLock extends BeanLockSupport
   {
  @@ -50,6 +61,7 @@
   
      private HashMap txLocks = new HashMap();
      private LinkedList txWaitQueue = new LinkedList();
  +   private boolean isReadOnlyTxLock = true;
   
      private int txIdGen = 0;
      private class TxLock
  @@ -136,6 +148,13 @@
            /* loop on lock wakeup and restart trying to schedule */
            threadScheduled = doSchedule(mi);
         }
  +      // Only set isReadOnlyTxLock if there was a transactional lock
  +      if (mi.getTransaction() != null)
  +      {
  +         // Promote the txlock into a writeLock if we're not a readonly method
  +         // isReadOnlyTxLock will be reset in nextTransaction()
  +         isReadOnlyTxLock = isReadOnlyTxLock && 
(((EntityContainer)container).isReadOnly() || 
container.getBeanMetaData().isMethodReadOnly(mi.getMethod().getName()));
  +      }
      }
      /**
       * doSchedule(Invocation)
  @@ -382,7 +401,7 @@
         }
   
         this.tx = null;
  -      
  +      this.isReadOnlyTxLock = true;
         // is there a waiting list?
         if (!txWaitQueue.isEmpty())
         {
  @@ -422,48 +441,31 @@
       * if we reach the count of zero it means the instance is free from threads (and 
reentrency)
       * we wake up the next thread in the currentLock
       */
  -   public void releaseMethodLock() 
  +   public void endInvocation(Invocation mi)
      { 
         numMethodLocks--;
         if (numMethodLocks == 0)
         {
            synchronized(methodLock) {methodLock.notify();}
  -      } 
  -   }
  -   
  -   /*
  -    * For debugging purposes
  -   private static int filecount = 0;
  -   
  -   private static synchronized void saveStackTrace(String msg)
  -   {
  -      System.out.println("saving stack trace");
  -      try
  -      {
  -         FileOutputStream fp = new FileOutputStream("d:/tmp/stacktraces/" + 
Integer.toString(filecount++) + ".txt");
  -         PrintStream ps = new PrintStream(fp);
  -         ps.println(msg);
  -         new Throwable().printStackTrace(ps);
  -         ps.close();
  -         fp.close();
  +         if (isReadOnlyTxLock && mi.getTransaction() != null)
  +         {
  +            if (isReadOnlyTxLock)
  +            {
  +               endTransaction(mi.getTransaction());
  +            }
  +         }
         }
  -      catch (Exception ignored) {}
  -      System.out.println("done saving stack trace");
  -
      }
  -   */
  -
  +   
      public void removeRef() 
      { 
         refs--;
         if (refs == 0 && txWaitQueue.size() > 0) 
         {
  -         //         saveStackTrace("****removing bean lock and it has tx's in 
QUEUE!***");
            throw new IllegalStateException("removing bean lock and it has tx's in 
QUEUE!");
         }
         else if (refs == 0 && this.tx != null) 
         {
  -         //         saveStackTrace("****removing bean lock and it has tx set!***");
            throw new IllegalStateException("removing bean lock and it has tx set!");
         }
         /*      else if (refs == 0)
  
  
  

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

Reply via email to