TransactionExclusiveLock is an exclusive lock that let the owner of the lock acquire several times the lock (but it needs to be released only once). Acquire supports timeout and graceful withdrawal of timed out requests.
TransactionExclusiveLock.java の 40 行で定義されています。
Public メソッド | |
| boolean | acquire (AbstractRequest request) |
| synchronized void | release () |
| boolean | isLocked () |
| long | getLocker () |
| ArrayList | getWaitingList () |
| synchronized boolean | isWaiting (long transactionId) |
Private 変数 | |
| boolean | isLocked = false |
| long | locker |
| ArrayList | waitingList = new ArrayList() |
|
|
Acquires an exclusive lock on this table. If the lock is already held by the same transaction as the given request, this method is non-blocking else the caller is blocked until the transaction holding the lock releases it at commit/rollback time.
TransactionExclusiveLock.java の 107 行で定義されています。 参照先 org.objectweb.cjdbc.common.sql.AbstractRequest.getTimeout(), org.objectweb.cjdbc.common.sql.AbstractRequest.getTransactionId(), org.objectweb.cjdbc.controller.scheduler.schema.TransactionExclusiveLock.isLocked, org.objectweb.cjdbc.controller.scheduler.schema.TransactionExclusiveLock.locker, org.objectweb.cjdbc.controller.scheduler.schema.TransactionExclusiveLock.release(), org.objectweb.cjdbc.common.sql.AbstractRequest.setTimeout(), と org.objectweb.cjdbc.controller.scheduler.schema.TransactionExclusiveLock.waitingList. 参照元 org.objectweb.cjdbc.controller.scheduler.singledb.SingleDBPessimisticTransactionLevelScheduler.scheduleNonSuspendedWriteRequest(), org.objectweb.cjdbc.controller.scheduler.raidb2.RAIDb2PessimisticTransactionLevelScheduler.scheduleNonSuspendedWriteRequest(), org.objectweb.cjdbc.controller.scheduler.raidb1.RAIDb1PessimisticTransactionLevelScheduler.scheduleNonSuspendedWriteRequest(), と org.objectweb.cjdbc.controller.scheduler.raidb0.RAIDb0PessimisticTransactionLevelScheduler.scheduleNonSuspendedWriteRequest().
00108 {
00109 long tid = request.getTransactionId();
00110
00111 synchronized (Thread.currentThread())
00112 {
00113 WaitingListElement wle = null;
00114 synchronized (this)
00115 {
00116 if (!isLocked)
00117 { // Lock is free, take it
00118 locker = tid;
00119 isLocked = true;
00120 return true;
00121 }
00122 else
00123 {
00124 if (locker == tid)
00125 return true; // We already have the lock
00126 else
00127 { // Wait for the lock
00128 wle = new WaitingListElement(Thread.currentThread(), tid);
00129 waitingList.add(wle);
00130 }
00131 }
00132 }
00133 // At this point, we have to wait for the lock.
00134 try
00135 {
00136 int timeout = request.getTimeout();
00137 if (timeout == 0)
00138 {
00139 Thread.currentThread().wait(); // No timeout
00140 // Note: isLocked and locker are already set.
00141 return true;
00142 }
00143 else
00144 { // Wait with timeout
00145 long start = System.currentTimeMillis();
00146 // Convert seconds to milliseconds for wait call
00147 long lTimeout = timeout * 1000;
00148 Thread.currentThread().wait(lTimeout);
00149 long end = System.currentTimeMillis();
00150 int remaining = (int) (lTimeout - (end - start));
00151 if (remaining > 0)
00152 { // Ok
00153 request.setTimeout(remaining);
00154 // Note: isLocked and locker are already set.
00155 return true;
00156 }
00157 else
00158 { // Too late, remove ourselves from the waiting list
00159 synchronized (this)
00160 {
00161 int idx = waitingList.indexOf(wle);
00162 if (idx == -1)
00163 // We got the lock before being able to acquire the lock on
00164 // this. Give the lock to the next one.
00165 release();
00166 else
00167 waitingList.remove(idx);
00168 }
00169 return false;
00170 }
00171 }
00172 }
00173 catch (InterruptedException ie)
00174 {
00175 synchronized (this)
00176 { // Something wrong happened, remove ourselves from the waiting list
00177 waitingList.remove(Thread.currentThread());
00178 }
00179 return false;
00180 }
00181 }
00182 }
|
|
|
Returns the transaction id of the lock owner. The return value is undefined if the lock is not owned (usually it is the last owner).
TransactionExclusiveLock.java の 223 行で定義されています。 参照先 org.objectweb.cjdbc.controller.scheduler.schema.TransactionExclusiveLock.locker. 参照元 org.objectweb.cjdbc.controller.scheduler.singledb.SingleDBPessimisticTransactionLevelScheduler.releaseLock(), org.objectweb.cjdbc.controller.scheduler.raidb2.RAIDb2PessimisticTransactionLevelScheduler.releaseLock(), org.objectweb.cjdbc.controller.scheduler.raidb1.RAIDb1PessimisticTransactionLevelScheduler.releaseLock(), org.objectweb.cjdbc.controller.scheduler.raidb0.RAIDb0PessimisticTransactionLevelScheduler.releaseLock(), org.objectweb.cjdbc.controller.scheduler.raidb1.RAIDb1OptimisticTransactionLevelScheduler.releaseLocks(), と org.objectweb.cjdbc.controller.scheduler.raidb1.RAIDb1OptimisticTransactionLevelScheduler.scheduleNonSuspendedWriteRequest().
00224 {
00225 return locker;
00226 }
|
|
|
Returns the waitingList.
TransactionExclusiveLock.java の 233 行で定義されています。 参照先 org.objectweb.cjdbc.controller.scheduler.schema.TransactionExclusiveLock.waitingList.
00234 {
00235 return waitingList;
00236 }
|
|
|
Returns
TransactionExclusiveLock.java の 212 行で定義されています。
00213 {
00214 return isLocked;
00215 }
|
|
|
Returns
TransactionExclusiveLock.java の 245 行で定義されています。 参照先 org.objectweb.cjdbc.controller.scheduler.schema.TransactionExclusiveLock.WaitingListElement.getTransactionId(), と org.objectweb.cjdbc.controller.scheduler.schema.TransactionExclusiveLock.waitingList.
00246 {
00247 WaitingListElement e;
00248 int size = waitingList.size();
00249 for (int i = 0; i < size; i++)
00250 {
00251 e = (WaitingListElement) waitingList.get(i);
00252 if (e.getTransactionId() == transactionId)
00253 return true;
00254 }
00255 return false;
00256 }
|
|
|
|
|
1.3.6