[jboss-svn-commits] JBL Code SVN: r30973 - labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Jan 7 13:33:48 EST 2010
Author: whitingjr
Date: 2010-01-07 13:33:48 -0500 (Thu, 07 Jan 2010)
New Revision: 30973
Modified:
labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/TransactionXADataSourceFactory.java
Log:
Added a shutdown hook to close the connection manager and connection pool.
Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/TransactionXADataSourceFactory.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/TransactionXADataSourceFactory.java 2010-01-07 15:58:42 UTC (rev 30972)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/TransactionXADataSourceFactory.java 2010-01-07 18:33:48 UTC (rev 30973)
@@ -115,6 +115,12 @@
IOUtils.closeQuietly(oStream);
}
}
+ /**
+ * Add a shutdown hook. This hook will attempt to close the connection manager and the
+ * connection pool. Thus ensuring the database does not exhaust it's pool of connections.
+ */
+ Shutdown shutdownHook = new Shutdown(this.connectionManager, this.pool);
+ Runtime.getRuntime().addShutdownHook(new Thread(shutdownHook));
}
public Object getDatasource()
@@ -242,4 +248,36 @@
{
return this.managedConnectionFactory.getPreparedStatementCacheSize();
}
+
+ /**
+ * This object is a convenience class to run the shutdown of a connection manager
+ * and pool.
+ *
+ * @author <a href="jwhiting at redhat.com">Jeremy Whiting</a>
+ * @version $Revision: 1.1 $
+ */
+ private class Shutdown implements Runnable
+ {
+ private final TxConnectionManager connectionManager;
+ private final BasePool basePool;
+ @Override
+ public void run()
+ {
+ logger.info("Shutting down DataSource Factory.");
+ try
+ {
+ this.connectionManager.stop();
+ this.basePool.shutdown();
+ }
+ catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
+
+ }
+ public Shutdown(final TxConnectionManager manager, final BasePool pool)
+ {
+ this.connectionManager = manager;
+ this.basePool = pool;
+ }
+ }
}
More information about the jboss-svn-commits
mailing list