org.jboss.ejb.plugins.lock
Class QueuedPessimisticEJBLock

java.lang.Object
  extended by org.jboss.ejb.plugins.lock.BeanLockSupport
      extended by org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock
All Implemented Interfaces:
BeanLock, BeanLockExt, org.jboss.util.deadlock.Resource
Direct Known Subclasses:
QueuedPessimisticEJBLockNoADE

public class QueuedPessimisticEJBLock
extends BeanLockSupport

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

Version:
$Revision: 1.32.6.3 $
Author:
Marc Fleury, Bill Burke, Peter Murray

Field Summary
protected  boolean deadlockDetection
          A flag that disables the deadlock detection check
protected  LockMonitor lockMonitor
           
 
Fields inherited from class org.jboss.ejb.plugins.lock.BeanLockSupport
container, id, refs, synched, synchedDepth, tx, txTimeout
 
Constructor Summary
QueuedPessimisticEJBLock()
           
 
Method Summary
protected  boolean doSchedule(Invocation mi)
          doSchedule(Invocation) doSchedule implements a particular policy for scheduling the threads coming in.
 void endInvocation(Invocation 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 transaction)
          Informs the lock that the given transaction has ended.
 boolean getDeadlockDetection()
           
protected  org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock.TxLock getTxLock(Transaction miTx)
           
protected  boolean isTxExpired(Transaction miTx)
           
protected  void nextTransaction()
           
 void removeRef()
          Decrement the reference count of this lock.
 void schedule(Invocation mi)
          This method implements the actual logic of the lock.
 void setContainer(Container container)
          set the ejb container of this lock.
 void setDeadlockDetection(boolean flag)
           
 String toString()
           
protected  boolean waitForTx(Transaction miTx, boolean trace)
          Wait until no other transaction is running with this lock.
 void wontSynchronize(Transaction 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
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 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 container)
Description copied from interface: BeanLock
set the ejb container of this lock.

Specified by:
setContainer in interface BeanLock
Overrides:
setContainer in class BeanLockSupport

getDeadlockDetection

public boolean getDeadlockDetection()

setDeadlockDetection

public void setDeadlockDetection(boolean flag)

getTxLock

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

isTxExpired

protected boolean isTxExpired(Transaction miTx)
                       throws Exception
Throws:
Exception

schedule

public void schedule(Invocation mi)
              throws Exception
Description copied from interface: BeanLock
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
Specified by:
schedule in class BeanLockSupport
Parameters:
mi - The method invocation that needs a lock.
Throws:
Exception

doSchedule

protected boolean doSchedule(Invocation mi)
                      throws 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:
Exception

waitForTx

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

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

nextTransaction

protected void nextTransaction()

endTransaction

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

Specified by:
endTransaction in interface BeanLock
Specified by:
endTransaction in class BeanLockSupport
Parameters:
transaction - The transaction that has ended.

wontSynchronize

public void wontSynchronize(Transaction trasaction)
Description copied from interface: BeanLock
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
Specified by:
wontSynchronize in class BeanLockSupport

endInvocation

public void endInvocation(Invocation 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
Specified by:
endInvocation in class BeanLockSupport

removeRef

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

Specified by:
removeRef in interface BeanLock
Overrides:
removeRef in class BeanLockSupport

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2002 JBoss Group, LLC. All Rights Reserved.