commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ozeigerm...@apache.org
Subject svn commit: r560725 - /commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/locking/RWLockManager.java
Date Sun, 29 Jul 2007 15:01:26 GMT
Author: ozeigermann
Date: Sun Jul 29 08:01:25 2007
New Revision: 560725

URL: http://svn.apache.org/viewvc?view=rev&rev=560725
Log:
Removed non-sense release code for non-current threads

Modified:
    commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/locking/RWLockManager.java

Modified: commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/locking/RWLockManager.java
URL: http://svn.apache.org/viewvc/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/locking/RWLockManager.java?view=diff&rev=560725&r1=560724&r2=560725
==============================================================================
--- commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/locking/RWLockManager.java
(original)
+++ commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/locking/RWLockManager.java
Sun Jul 29 08:01:25 2007
@@ -42,7 +42,7 @@
 
     @Override
     public void endWork() {
-        release(Thread.currentThread());
+        release();
     }
 
     @Override
@@ -150,7 +150,8 @@
         if (time == 0) {
             locked = lock.tryLock();
         } else {
-            locked = doTrickyYetEfficientLockOnlyIfThisCanNotCauseADeadlock(lock, unit.toMillis(time));
+            locked = doTrickyYetEfficientLockOnlyIfThisCanNotCauseADeadlock(lock, unit
+                    .toMillis(time));
         }
         if (locked) {
             locks.add(lock);
@@ -275,9 +276,12 @@
         Set<Thread> threads = effectiveGlobalTimeouts.keySet();
         for (Thread thread : threads) {
             if (hasTimedOut(thread)) {
-                // TODO: We need to record this thread has timed out to produce
+                // TODO #1: We need to record this thread has timed out to produce
                 // a meaningful exception when it tries to continue its work
-                release(thread);
+                // TODO #2: If would be even better if we could actively release
+                // its locks, but only the thread that acquired a lock can
+                // release it. An extended implementation of ReentrantLock would
+                // help.
                 thread.interrupt();
             }
 
@@ -290,8 +294,8 @@
 
     }
 
-    protected void release(Thread thread) {
-        Set<Lock> locks = locksForThreads.get(thread);
+    protected void release() {
+        Set<Lock> locks = locksForThreads.get(Thread.currentThread());
         // graceful reaction...
         if (locks == null) {
             return;
@@ -310,7 +314,7 @@
             }
         }
 
-        locksForThreads.remove(thread);
+        locksForThreads.remove(Thread.currentThread());
     }
 
 }



Mime
View raw message