You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Robert Anderson <ra...@gmail.com> on 2015/12/17 13:47:06 UTC

[Tomcat-JDBC] ResetAbandoned doesn't trigger JdbcInterceptors

Hi,

When a connection is closed by "ResetAbandoned" the invoke() method from
JdbcInterceptor is not called. Is it the expected behaviour?

-->server.xml

       <Resource name="jdbc/cacheapp" auth="Container"
type="javax.sql.DataSource" removeAbandoned="true"
removeAbandonedTimeout="30"
                                   maxActive="5" maxIdle="1"
initialSize="0" minIdle="0" maxWait="5000"
                   validationQuery="select 1"
                   maxAge="1"
                   testOnBorrow="true"
  factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
  alternateUsernameAllowed="true"
 jdbcInterceptors="pool.ExampleInterceptor"
  username="tomcat" password="example"
driverClassName="com.intersys.jdbc.CacheDriver"
  url="jdbc:Cache://serverip:1972/NS"/>

--> pool.ExampleInterceptor

public class ExampleInterceptor extends JdbcInterceptor {


    public Object invoke(Object proxy, Method method, Object[] args) throws
Throwable {
        if (method.getName() == CLOSE_VAL) {
            System.out.println("Interceptor called."); //Doesn't happen but
connection is really closed (checked via JMX)
        }
        return super.invoke(proxy, method, args);
    }

--> JSP to simulate long running query

<%@ page session="false" import="java.sql.*,javax.naming.*, javax.sql.*,
java.util.*" contentType="text/html" %><%
Connection conn = null;
try {
        Context ctx = new InitialContext();
        DataSource ds =
(DataSource)ctx.lookup("java:comp/env/jdbc/cacheapp");
        conn = ds.getConnection();
Thread.sleep(60000);
} catch (Exception e) {
        out.print(e.getMessage());
} finally {
        if (conn != null) {
                try {
                        //conn.close(); //Don't close to force
RemovedAbandonedTimeout
                } catch (Exception e) {}
        }
}
%>


Server version: Apache Tomcat/7.0.65
Server built:   Oct 9 2015 08:36:58 UTC
Server number:  7.0.65.0
OS Name:        Linux
OS Version:     2.6.18-194.32.1.el5
Architecture:   amd64
JVM Version:    1.7.0_80-b15
JVM Vendor:     Oracle Corporation

Thanks in advance.

Robert