On 7. August 2014 23:04:12 MESZ, fha...@apache.org wrote: >Author: fhanik >Date: Thu Aug 7 21:04:11 2014 >New Revision: 1616594 > >URL: http://svn.apache.org/r1616594 >Log: >Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=54227 >MaxAge should be honored upon borrow as well, to assure that no >connection is ever used if it has been connected longer than designated >time. > >Added: >tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/bugs/Bug54227.java > (with props) >Modified: >tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java >tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PooledConnection.java > >Modified: >tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java >URL: >http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java?rev=1616594&r1=1616593&r2=1616594&view=diff >============================================================================== >--- >tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java >(original) >+++ >tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java >Thu Aug 7 21:04:11 2014 >@@ -279,6 +279,10 @@ public class ConnectionPool { >* @throws SQLException if an interceptor can't be configured, if the >proxy can't be instantiated > */ >protected Connection setupConnection(PooledConnection con) throws >SQLException { >+ //check if it's been sitting in the pool too long >+ if (con.isMaxAgeExpired()) { >+ con.reconnect(); >+ } > //fetch previously cached interceptor proxy - one per connection > JdbcInterceptor handler = con.getHandler(); > if (handler==null) { >@@ -862,11 +866,8 @@ public class ConnectionPool { > if (isClosed()) return true; > if (!con.validate(action)) return true; > if (!terminateTransaction(con)) return true; >- if (getPoolProperties().getMaxAge()>0 ) { >- return (System.currentTimeMillis()-con.getLastConnected()) >> getPoolProperties().getMaxAge(); >- } else { >- return false; >- } >+ if (con.isMaxAgeExpired()) return true; >+ else return false;
Wouldn't it be nicer to directly return con.isMaxAgeExpired()? Regards Felix > } > > /** > >Modified: >tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PooledConnection.java >URL: >http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PooledConnection.java?rev=1616594&r1=1616593&r2=1616594&view=diff >============================================================================== >--- >tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PooledConnection.java >(original) >+++ >tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PooledConnection.java >Thu Aug 7 21:04:11 2014 >@@ -318,6 +318,19 @@ public class PooledConnection { > } > > /** >+ * Returns true if the connection has been connected more than >+ * {@link PoolConfiguration#getMaxAge()} milliseconds. false >otherwise. >+ * @return Returns true if the connection has been connected more >than >+ * {@link PoolConfiguration#getMaxAge()} milliseconds. false >otherwise. >+ */ >+ public boolean isMaxAgeExpired() { >+ if (getPoolProperties().getMaxAge()>0 ) { >+ return (System.currentTimeMillis() - getLastConnected()) > >getPoolProperties().getMaxAge(); >+ } else { >+ return false; >+ } >+ } >+ /** >* Issues a call to {@link #disconnect(boolean)} with the argument false >followed by a call to > * {@link #connect()} > * @throws SQLException if the call to {@link #connect()} fails. > >Added: >tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/bugs/Bug54227.java >URL: >http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/bugs/Bug54227.java?rev=1616594&view=auto >============================================================================== >--- >tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/bugs/Bug54227.java >(added) >+++ >tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/bugs/Bug54227.java >Thu Aug 7 21:04:11 2014 >@@ -0,0 +1,65 @@ >+/* >+ * Licensed to the Apache Software Foundation (ASF) under one or more >+ * contributor license agreements. See the NOTICE file distributed >with >+ * this work for additional information regarding copyright ownership. >+ * The ASF licenses this file to You under the Apache License, Version >2.0 >+ * (the "License"); you may not use this file except in compliance >with >+ * the License. You may obtain a copy of the License at >+ * >+ * http://www.apache.org/licenses/LICENSE-2.0 >+ * >+ * Unless required by applicable law or agreed to in writing, software >+ * distributed under the License is distributed on an "AS IS" BASIS, >+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or >implied. >+ * See the License for the specific language governing permissions and >+ * limitations under the License. >+ */ >+package org.apache.tomcat.jdbc.bugs; >+ >+import org.apache.tomcat.jdbc.pool.DataSource; >+import org.apache.tomcat.jdbc.pool.PoolProperties; >+import org.apache.tomcat.jdbc.test.DefaultProperties; >+import org.junit.Test; >+ >+import javax.sql.PooledConnection; >+import java.sql.Connection; >+import java.sql.SQLException; >+ >+import static org.junit.Assert.assertNotSame; >+import static org.junit.Assert.assertSame; >+ >+public class Bug54227 { >+ >+ >+ public Bug54227() { >+ } >+ >+ @Test >+ public void testPool() throws SQLException, InterruptedException { >+ PoolProperties poolProperties = new DefaultProperties(); >+ poolProperties.setMinIdle(0); >+ poolProperties.setInitialSize(0); >+ poolProperties.setMaxActive(1); >+ poolProperties.setMaxWait(5000); >+ poolProperties.setMaxAge(100); >+ poolProperties.setRemoveAbandoned(false); >+ >+ final DataSource ds = new DataSource(poolProperties); >+ Connection con; >+ Connection actual1; >+ Connection actual2; >+ >+ con = ds.getConnection(); >+ actual1 = ((PooledConnection)con).getConnection(); >+ con.close(); >+ con = ds.getConnection(); >+ actual2 = ((PooledConnection)con).getConnection(); >+ assertSame(actual1, actual2); >+ con.close(); >+ Thread.sleep(150); >+ con = ds.getConnection(); >+ actual2 = ((PooledConnection)con).getConnection(); >+ assertNotSame(actual1, actual2); >+ con.close(); >+ } >+} >\ No newline at end of file > >Propchange: >tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/bugs/Bug54227.java >------------------------------------------------------------------------------ > svn:eol-style = native > > > >--------------------------------------------------------------------- >To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org >For additional commands, e-mail: dev-h...@tomcat.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org