Author: markt Date: Mon Jan 14 09:08:30 2013 New Revision: 1432845 URL: http://svn.apache.org/viewvc?rev=1432845&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/MultiLockFairBlockingQueue.java tomcat/trunk/res/findbugs/filter-false-positives.xml Modified: tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/MultiLockFairBlockingQueue.java URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/MultiLockFairBlockingQueue.java?rev=1432845&r1=1432844&r2=1432845&view=diff ============================================================================== --- tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/MultiLockFairBlockingQueue.java (original) +++ tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/MultiLockFairBlockingQueue.java Mon Jan 14 09:08:30 2013 @@ -145,10 +145,9 @@ public class MultiLockFairBlockingQueue< int idx = getNextPoll(); E result = null; final ReentrantLock lock = this.locks[idx]; - 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[idx].poll(); if (result==null && timeout>0) { @@ -171,9 +170,8 @@ public class MultiLockFairBlockingQueue< //we have an object, release lock.unlock(); } - error = false; } finally { - if (error && lock.isHeldByCurrentThread()) { + if (lock.isHeldByCurrentThread()) { lock.unlock(); } } @@ -188,29 +186,23 @@ public class MultiLockFairBlockingQueue< int idx = getNextPoll(); Future<E> result = null; final ReentrantLock lock = this.locks[idx]; - 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[idx].poll(); if (item==null) { //queue is empty, add ourselves as waiters ExchangeCountDownLatch<E> c = new ExchangeCountDownLatch<>(1); waiters[idx].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=1432845&r1=1432844&r2=1432845&view=diff ============================================================================== --- tomcat/trunk/res/findbugs/filter-false-positives.xml (original) +++ tomcat/trunk/res/findbugs/filter-false-positives.xml Mon Jan 14 09:08:30 2013 @@ -242,6 +242,12 @@ <Bug code="ES" /> </Match> <Match> + <!-- Lock is released --> + <Class name="org.apache.tomcat.jdbc.pool.MultiLockFairBlockingQueue" /> + <Method name="poll" /> + <Bug code="UL" /> + </Match> + <Match> <!-- Wait is in AprSocket --> <Class name="org.apache.tomcat.jni.socket.AprSocketContext$AprPoller" /> <Method name="run"/> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org