org.jboss.ejb.plugins.lock
Class QueuedPessimisticEJBLock

java.lang.Object
  extended byorg.jboss.ejb.plugins.lock.BeanLockSupport (src) 
      extended byorg.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock
All Implemented Interfaces:
BeanLock (src) , BeanLockExt (src) , Resource (src)
Direct Known Subclasses:
QueuedPessimisticEJBLockNoADE (src)

public class QueuedPessimisticEJBLock
extends BeanLockSupport (src)

This class is holds threads awaiting the transactional lock to be free in a fair FIFO transactional queue. Non-transactional threads are also put in this wait queue as well. Unlike SimplePessimisticEJBLock which notifies all threads on transaction completion, this class pops the next waiting transaction from the queue and notifies only those threads waiting associated with that transaction. This class should perform better than Simple on high contention loads. Holds all locks for entity beans, not used for stateful.

All BeanLocks have a reference count. 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


Field Summary
protected  boolean deadlockDetection
          A flag that disables the deadlock detection check
protected  LockMonitor (src) lockMonitor
           
 
Fields inherited from class org.jboss.ejb.plugins.lock.BeanLockSupport (src)
container, id, refs, synched, synchedDepth, tx, txTimeout
 
Constructor Summary
QueuedPessimisticEJBLock()
           
 
Method Summary
protected  boolean doSchedule(Invocation (src)  mi)
          doSchedule(Invocation) doSchedule implements a particular policy for scheduling the threads coming in.
 void endInvocation(Invocation (src)  mi)
          releaseMethodLock 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
 void endTransaction(Transaction (src)  transaction)
          Informs the lock that the given transaction has ended.
 boolean getDeadlockDetection()
           
protected  org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock.TxLock getTxLock(Transaction (src)  miTx)
           
protected  boolean isTxExpired(Transaction (src)  miTx)
           
protected  void nextTransaction()
           
 void removeRef()
          Decrement the reference count of this lock.
 void schedule(Invocation (src)  mi)
          This method implements the actual logic of the lock.
 void setContainer(Container (src)  container)
          set the ejb container of this lock.
 void setDeadlockDetection(boolean flag)
           
 java.lang.String toString()
           
protected  boolean waitForTx(Transaction (src)  miTx, boolean trace)
          Wait until no other transaction is running with this lock.
 void wontSynchronize(Transaction (src)  trasaction)
          Signifies to the lock that the transaction will not Synchronize (Tx demarcation not seen).
 
Methods inherited from class org.jboss.ejb.plugins.lock.BeanLockSupport (src)
addRef, attemptSync, getId, getRefs, getResourceHolder, getTransaction, releaseSync, setId, setTimeout, setTransaction, sync
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

lockMonitor

protected LockMonitor (src)  lockMonitor

deadlockDetection

protected boolean deadlockDetection
A flag that disables the deadlock detection check

Constructor Detail

QueuedPessimisticEJBLock

public QueuedPessimisticEJBLock()
Method Detail

setContainer

public void setContainer(Container (src)  container)
Description copied from interface: BeanLock (src)
set the ejb container of this lock.

Specified by:
setContainer in interface BeanLock (src)
Overrides:
setContainer in class BeanLockSupport (src)

getDeadlockDetection

public boolean getDeadlockDetection()

setDeadlockDetection

public void setDeadlockDetection(boolean flag)

getTxLock

protected org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock.TxLock getTxLock(Transaction (src)  miTx)

isTxExpired

protected boolean isTxExpired(Transaction (src)  miTx)
                       throws java.lang.Exception
Throws:
java.lang.Exception

schedule

public void schedule(Invocation (src)  mi)
              throws java.lang.Exception
Description copied from interface: BeanLock (src)
This method implements the actual logic of the lock. In the case of an EJB lock it must at least implement the serialization of calls

Specified by:
schedule in interface BeanLock (src)
Specified by:
schedule in class BeanLockSupport (src)
Throws:
java.lang.Exception

doSchedule

protected boolean doSchedule(Invocation (src)  mi)
                      throws java.lang.Exception
doSchedule(Invocation) doSchedule implements a particular policy for scheduling the threads coming in. There is always the spec required "serialization" but we can add custom scheduling in here Synchronizing on lock: a failure to get scheduled must result in a wait() call and a release of the lock. Schedulation must return with lock.

Throws:
java.lang.Exception

waitForTx

protected boolean waitForTx(Transaction (src)  miTx,
                            boolean trace)
                     throws java.lang.Exception
Wait until no other transaction is running with this lock.

Returns:
Returns true if this thread was scheduled in txWaitQueue
Throws:
java.lang.Exception

nextTransaction

protected void nextTransaction()

endTransaction

public void endTransaction(Transaction (src)  transaction)
Description copied from interface: BeanLock (src)
Informs the lock that the given transaction has ended.

Specified by:
endTransaction in interface BeanLock (src)
Specified by:
endTransaction in class BeanLockSupport (src)

wontSynchronize

public void wontSynchronize(Transaction (src)  trasaction)
Description copied from interface: BeanLock (src)
Signifies to the lock that the transaction will not Synchronize (Tx demarcation not seen).

OSH: This method does not seem to be called from anywhere. What is it meant for? To be called on a timeout before the transaction has terminated?

Specified by:
wontSynchronize in interface BeanLock (src)
Specified by:
wontSynchronize in class BeanLockSupport (src)

endInvocation

public void endInvocation(Invocation (src)  mi)
releaseMethodLock 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

Specified by:
endInvocation in interface BeanLock (src)
Specified by:
endInvocation in class BeanLockSupport (src)

removeRef

public void removeRef()
Description copied from interface: BeanLock (src)
Decrement the reference count of this lock.

Specified by:
removeRef in interface BeanLock (src)
Overrides:
removeRef in class BeanLockSupport (src)

toString

public java.lang.String toString()