tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amit shah <amits...@gmail.com>
Subject Closing tomcat jdbc connection pool
Date Fri, 02 Mar 2012 06:23:45 GMT
Hello,
          I am using the tomcat7 jdbc pool independently by deploying the
jdbc pool and juli jars with my web application. I would like to get
suggestions on how to close the connection pool when the application server
is stopped.
          The below code doesn't work as expected

        public void shutdown(DataSource dataSource) {
                org.apache.tomcat.jdbc.pool.DataSource tomcatDataSource =
null;
                try {
                   tomcatDataSource =
dataSource.unwrap(org.apache.tomcat.jdbc.pool.DataSource.class);
                } catch (SQLException e) {
                   throw new RuntimeException(e);
                }
                tomcatDataSource.close();
        }


        The reason being the unwrap implementation
in org.apache.tomcat.jdbc.pool.DataSource returns null. Hence a NPE.
        Casting the dataSource instance to
directly org.apache.tomcat.jdbc.pool.DataSource isn't an option because
during creation we decorate the data source for various reasons like
logging, changing the isolation level etc.

Any ideas on how could the close method be called?

Thank you.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message