ozeigermann 2004/12/19 02:10:13
Modified: transaction/src/java/org/apache/commons/transaction/locking
GenericLockManager.java
Log:
Refined lock owners synchronization
Revision Changes Path
1.7 +22 -16
jakarta-commons/transaction/src/java/org/apache/commons/transaction/locking/GenericLockManager.java
Index: GenericLockManager.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/transaction/src/java/org/apache/commons/transaction/locking/GenericLockManager.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- GenericLockManager.java 19 Dec 2004 03:07:04 -0000 1.6
+++ GenericLockManager.java 19 Dec 2004 10:10:13 -0000 1.7
@@ -204,6 +204,8 @@
LockException.CODE_DEADLOCK_VICTIM,
resourceId);
}
+ // if there are owners we conflict with lets see if one
of them globally times
+ // out earlier than this lock, if so we will wake up
then to check again
long nextConflictTimeout =
getNextGlobalConflictTimeout(conflicts);
if (nextConflictTimeout != -1 && nextConflictTimeout <
waitEnd) {
timeoutMSecs = nextConflictTimeout - now;
@@ -265,10 +267,12 @@
}
Set locks = (Set) globalOwners.get(ownerId);
if (locks != null) {
- for (Iterator it = locks.iterator(); it.hasNext();) {
- GenericLock lock = (GenericLock) it.next();
- lock.release(ownerId);
- it.remove();
+ synchronized (locks) {
+ for (Iterator it = locks.iterator(); it.hasNext();) {
+ GenericLock lock = (GenericLock) it.next();
+ lock.release(ownerId);
+ it.remove();
+ }
}
}
}
@@ -279,19 +283,21 @@
public Set getAll(Object ownerId) {
Set locks = (Set) globalOwners.get(ownerId);
if (locks == null) {
- locks = new HashSet();
- globalOwners.put(ownerId, locks);
+ return new HashSet();
+ } else {
+ return locks;
}
- return locks;
}
protected void addOwner(Object ownerId, GenericLock lock) {
- Set locks = (Set) globalOwners.get(ownerId);
- if (locks == null) {
- locks = new HashSet();
- globalOwners.put(ownerId, locks);
+ synchronized (globalOwners) {
+ Set locks = (Set) globalOwners.get(ownerId);
+ if (locks == null) {
+ locks = Collections.synchronizedSet(new HashSet());
+ globalOwners.put(ownerId, locks);
+ }
+ locks.add(lock);
}
- locks.add(lock);
}
protected void removeOwner(Object ownerId, GenericLock lock) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]