mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-14 21:43:11 +00:00
Improved cleanup of database resources when web application is unloaded
git-svn-id: http://scm.dspace.org/svn/repo/branches/dspace-1_5_x@2926 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
@@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
* DSpaceContextListener.java
|
||||||
|
*
|
||||||
|
* Version: $Revision: 1.3 $
|
||||||
|
*
|
||||||
|
* Date: $Date: 2006/07/05 21:39:29 $
|
||||||
|
*
|
||||||
|
* Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
|
||||||
|
* Institute of Technology. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* - Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* - Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* - Neither the name of the Hewlett-Packard Company nor the name of the
|
||||||
|
* Massachusetts Institute of Technology nor the names of their
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||||
|
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||||
|
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
||||||
|
* DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.dspace.app.util;
|
||||||
|
|
||||||
|
import org.dspace.storage.rdbms.DatabaseManager;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContextListener;
|
||||||
|
import javax.servlet.ServletContextEvent;
|
||||||
|
import java.beans.Introspector;
|
||||||
|
import java.sql.Driver;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to initialise / cleanup resources used by DSpace when the web application
|
||||||
|
* is started or stopped
|
||||||
|
*/
|
||||||
|
public class DSpaceContextListener implements ServletContextListener
|
||||||
|
{
|
||||||
|
private static Logger log = Logger.getLogger(DSpaceContextListener.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialise any resources required by the application
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
public void contextInitialized(ServletContextEvent event)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean up resources used by the application when stopped
|
||||||
|
*
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
public void contextDestroyed(ServletContextEvent event)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Remove the database pool
|
||||||
|
DatabaseManager.shutdown();
|
||||||
|
|
||||||
|
// Clean out the introspector
|
||||||
|
Introspector.flushCaches();
|
||||||
|
|
||||||
|
// Remove any drivers registered by this classloader
|
||||||
|
for (Enumeration e = DriverManager.getDrivers(); e.hasMoreElements();)
|
||||||
|
{
|
||||||
|
Driver driver = (Driver) e.nextElement();
|
||||||
|
if (driver.getClass().getClassLoader() == getClass().getClassLoader())
|
||||||
|
{
|
||||||
|
DriverManager.deregisterDriver(driver);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Throwable e)
|
||||||
|
{
|
||||||
|
log.error("Failled to cleanup ClassLoader for webapp", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1429,10 +1429,8 @@ public class DatabaseManager
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Register basic JDBC driver
|
// Register basic JDBC driver
|
||||||
Class driverClass = Class.forName(ConfigurationManager
|
Class.forName(ConfigurationManager.getProperty("db.driver"));
|
||||||
.getProperty("db.driver"));
|
Class.forName("org.apache.commons.dbcp.PoolingDriver");
|
||||||
Driver basicDriver = (Driver) driverClass.newInstance();
|
|
||||||
DriverManager.registerDriver(basicDriver);
|
|
||||||
|
|
||||||
// Read pool configuration parameter or use defaults
|
// Read pool configuration parameter or use defaults
|
||||||
// Note we check to see if property is null; getIntProperty returns
|
// Note we check to see if property is null; getIntProperty returns
|
||||||
@@ -1459,7 +1457,7 @@ public class DatabaseManager
|
|||||||
{
|
{
|
||||||
maxIdle = -1;
|
maxIdle = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean useStatementPool = ConfigurationManager.getBooleanProperty("db.statementpool",true);
|
boolean useStatementPool = ConfigurationManager.getBooleanProperty("db.statementpool",true);
|
||||||
|
|
||||||
// Create object pool
|
// Create object pool
|
||||||
@@ -1529,14 +1527,15 @@ public class DatabaseManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Finally, we create the PoolingDriver itself...
|
// Finally, we get the PoolingDriver itself...
|
||||||
//
|
//
|
||||||
PoolingDriver driver = new PoolingDriver();
|
PoolingDriver driver = (PoolingDriver)DriverManager.getDriver("jdbc:apache:commons:dbcp:");
|
||||||
|
|
||||||
//
|
//
|
||||||
// ...and register our pool with it.
|
// ...and register our pool with it.
|
||||||
//
|
//
|
||||||
driver.registerPool(poolName, connectionPool);
|
if (driver != null)
|
||||||
|
driver.registerPool(poolName, connectionPool);
|
||||||
|
|
||||||
// Old SimplePool init
|
// Old SimplePool init
|
||||||
//DriverManager.registerDriver(new SimplePool());
|
//DriverManager.registerDriver(new SimplePool());
|
||||||
|
@@ -124,6 +124,12 @@
|
|||||||
<url-pattern>/view-workspaceitem</url-pattern>
|
<url-pattern>/view-workspaceitem</url-pattern>
|
||||||
</filter-mapping>
|
</filter-mapping>
|
||||||
|
|
||||||
|
<!-- Listener to initialise / clean up the application -->
|
||||||
|
<listener>
|
||||||
|
<listener-class>org.dspace.app.util.DSpaceContextListener</listener-class>
|
||||||
|
</listener>
|
||||||
|
|
||||||
|
|
||||||
<!-- Servlets -->
|
<!-- Servlets -->
|
||||||
|
|
||||||
<!-- DSpace configuration initialisation. This needs to be loaded before
|
<!-- DSpace configuration initialisation. This needs to be loaded before
|
||||||
|
@@ -49,6 +49,12 @@
|
|||||||
</description>
|
</description>
|
||||||
</context-param>
|
</context-param>
|
||||||
|
|
||||||
|
<!-- Listener to initialise / clean up the application -->
|
||||||
|
<listener>
|
||||||
|
<listener-class>org.dspace.app.util.DSpaceContextListener</listener-class>
|
||||||
|
</listener>
|
||||||
|
|
||||||
|
|
||||||
<!-- Servlet Configuration ========================================== -->
|
<!-- Servlet Configuration ========================================== -->
|
||||||
|
|
||||||
<servlet>
|
<servlet>
|
||||||
|
Reference in New Issue
Block a user