This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 7.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/7.0.x by this push: new 858ead0 Generics: AbandonedObjectPool 858ead0 is described below commit 858ead0fa9facb2083afecdf97cc09875823f4ac Author: Mark Thomas <ma...@apache.org> AuthorDate: Fri Mar 22 11:02:10 2019 +0000 Generics: AbandonedObjectPool --- .../tomcat/dbcp/dbcp/AbandonedObjectPool.java | 50 +++++++++++----------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/java/org/apache/tomcat/dbcp/dbcp/AbandonedObjectPool.java b/java/org/apache/tomcat/dbcp/dbcp/AbandonedObjectPool.java index 5cd5e5d..983ed3d 100644 --- a/java/org/apache/tomcat/dbcp/dbcp/AbandonedObjectPool.java +++ b/java/org/apache/tomcat/dbcp/dbcp/AbandonedObjectPool.java @@ -5,9 +5,9 @@ * 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. @@ -29,20 +29,20 @@ import org.apache.tomcat.dbcp.pool.impl.GenericObjectPool; * tracks JDBC connections and can recover abandoned db connections. * If logAbandoned=true, a stack trace will be printed for any * abandoned db connections recovered. - * + * * @author Glenn L. Nielsen */ -public class AbandonedObjectPool extends GenericObjectPool { +public class AbandonedObjectPool<T extends AbandonedTrace> extends GenericObjectPool<T> { - /** - * DBCP AbandonedConfig + /** + * DBCP AbandonedConfig */ private final AbandonedConfig config; - + /** * A list of connections in use */ - private final List trace = new ArrayList(); + private final List<T> trace = new ArrayList<T>(); /** * Create an ObjectPool which tracks db connections. @@ -50,7 +50,7 @@ public class AbandonedObjectPool extends GenericObjectPool { * @param factory PoolableObjectFactory used to create this * @param config configuration for abandoned db connections */ - public AbandonedObjectPool(PoolableObjectFactory factory, + public AbandonedObjectPool(PoolableObjectFactory<T> factory, AbandonedConfig config) { super(factory); this.config = config; @@ -63,22 +63,22 @@ public class AbandonedObjectPool extends GenericObjectPool { * have been idle > removeAbandonedTimeout and * getNumActive() > getMaxActive() - 3 and * getNumIdle() < 2 - * + * * @return Object JDBC Connection - * @throws Exception if an exception occurs retrieving a + * @throws Exception if an exception occurs retrieving a * connection from the pool */ @Override - public Object borrowObject() throws Exception { + public T borrowObject() throws Exception { if (config != null && config.getRemoveAbandoned() && (getNumIdle() < 2) && (getNumActive() > getMaxActive() - 3) ) { removeAbandoned(); } - Object obj = super.borrowObject(); - if (obj instanceof AbandonedTrace) { - ((AbandonedTrace) obj).setStackTrace(); + T obj = super.borrowObject(); + if (obj != null) { + obj.setStackTrace(); } if (obj != null && config != null && config.getRemoveAbandoned()) { synchronized (trace) { @@ -96,7 +96,7 @@ public class AbandonedObjectPool extends GenericObjectPool { * to the pool */ @Override - public void returnObject(Object obj) throws Exception { + public void returnObject(T obj) throws Exception { if (config != null && config.getRemoveAbandoned()) { synchronized (trace) { boolean foundObject = trace.remove(obj); @@ -115,7 +115,7 @@ public class AbandonedObjectPool extends GenericObjectPool { * @throws Exception if an exception occurs invalidating the object */ @Override - public void invalidateObject(Object obj) throws Exception { + public void invalidateObject(T obj) throws Exception { if (config != null && config.getRemoveAbandoned()) { synchronized (trace) { boolean foundObject = trace.remove(obj); @@ -124,7 +124,7 @@ public class AbandonedObjectPool extends GenericObjectPool { } } } - super.invalidateObject(obj); + super.invalidateObject(obj); } /** @@ -135,11 +135,11 @@ public class AbandonedObjectPool extends GenericObjectPool { // Generate a list of abandoned connections to remove long now = System.currentTimeMillis(); long timeout = now - (config.getRemoveAbandonedTimeout() * 1000); - ArrayList remove = new ArrayList(); + ArrayList<T> remove = new ArrayList<T>(); synchronized (trace) { - Iterator it = trace.iterator(); + Iterator<T> it = trace.iterator(); while (it.hasNext()) { - AbandonedTrace pc = (AbandonedTrace) it.next(); + T pc = it.next(); if (pc.getLastUsed() > timeout) { continue; } @@ -150,18 +150,18 @@ public class AbandonedObjectPool extends GenericObjectPool { } // Now remove the abandoned connections - Iterator it = remove.iterator(); + Iterator<T> it = remove.iterator(); while (it.hasNext()) { - AbandonedTrace pc = (AbandonedTrace) it.next(); + T pc = it.next(); if (config.getLogAbandoned()) { pc.printStackTrace(); - } + } try { invalidateObject(pc); } catch (Exception e) { e.printStackTrace(); } - + } } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org