You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2013/01/14 10:02:57 UTC

svn commit: r1432842 - in /tomcat/trunk: modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/FairBlockingQueue.java res/findbugs/filter-false-positives.xml

Author: markt
Date: Mon Jan 14 09:02:56 2013
New Revision: 1432842

URL: http://svn.apache.org/viewvc?rev=1432842&view=rev
Log:
Simplify locking code.
Mark remaining issues as false positives

Modified:
    tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/FairBlockingQueue.java
    tomcat/trunk/res/findbugs/filter-false-positives.xml

Modified: tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/FairBlockingQueue.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/FairBlockingQueue.java?rev=1432842&r1=1432841&r2=1432842&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/FairBlockingQueue.java (original)
+++ tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/FairBlockingQueue.java Mon Jan 14 09:02:56 2013
@@ -134,10 +134,9 @@ public class FairBlockingQueue<E> implem
     public E poll(long timeout, TimeUnit unit) throws InterruptedException {
         E result = null;
         final ReentrantLock lock = this.lock;
-        boolean error = true;
-        //acquire the global lock until we know what to do
-        lock.lock();
         try {
+            //acquire the global lock until we know what to do
+            lock.lock();
             //check to see if we have objects
             result = items.poll();
             if (result==null && timeout>0) {
@@ -160,9 +159,8 @@ public class FairBlockingQueue<E> implem
                 //we have an object, release
                 lock.unlock();
             }
-            error = false;
         } finally {
-            if (error && lock.isHeldByCurrentThread()) {
+            if (lock.isHeldByCurrentThread()) {
                 lock.unlock();
             }
         }
@@ -176,29 +174,23 @@ public class FairBlockingQueue<E> implem
     public Future<E> pollAsync() {
         Future<E> result = null;
         final ReentrantLock lock = this.lock;
-        boolean error = true;
-        //grab the global lock
-        lock.lock();
         try {
+            //grab the global lock
+            lock.lock();
             //check to see if we have objects in the queue
             E item = items.poll();
             if (item==null) {
                 //queue is empty, add ourselves as waiters
                 ExchangeCountDownLatch<E> c = new ExchangeCountDownLatch<>(1);
                 waiters.addLast(c);
-                lock.unlock();
                 //return a future that will wait for the object
                 result = new ItemFuture<>(c);
             } else {
-                lock.unlock();
                 //return a future with the item
                 result = new ItemFuture<>(item);
             }
-            error = false;
         } finally {
-            if (error && lock.isHeldByCurrentThread()) {
-                lock.unlock();
-            }
+            lock.unlock();
         }
         return result;
     }

Modified: tomcat/trunk/res/findbugs/filter-false-positives.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/res/findbugs/filter-false-positives.xml?rev=1432842&r1=1432841&r2=1432842&view=diff
==============================================================================
--- tomcat/trunk/res/findbugs/filter-false-positives.xml (original)
+++ tomcat/trunk/res/findbugs/filter-false-positives.xml Mon Jan 14 09:02:56 2013
@@ -230,6 +230,12 @@
     <Bug code="Nm" />
   </Match>
   <Match>
+    <!-- Lock is released -->
+    <Class name="org.apache.tomcat.jdbc.pool.FairBlockingQueue" />
+    <Method name="poll" />
+    <Bug code="UL" />
+  </Match>
+  <Match>
     <!-- Use of == is deliberate -->
     <Class name="org.apache.tomcat.jdbc.pool.JdbcInterceptor" />
     <Method name="compare" />



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org