package org.fiware.apps.marketplace.utils;

import java.util.Enumeration;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.slf4j.LoggerFactory;

import ch.qos.logback.classic.LoggerContext;

public class ContextFinalizer implements ServletContextListener {

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		// Nothing to do...
	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		try {
			com.mysql.jdbc.AbandonedConnectionCleanupThread.shutdown();
		} catch (Throwable t) {
			
		}
		
		// This manually deregisters JDBC driver, which prevents Tomcat 7 from complaining about memory leaks
		Enumeration<java .sql.Driver> drivers = java.sql.DriverManager.getDrivers();
		while (drivers.hasMoreElements()) {
			java.sql.Driver driver = drivers.nextElement();
			try {
				java.sql.DriverManager.deregisterDriver(driver);
			} catch (Throwable t) {}
		}
		
		// Destroy loggers
		LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
		lc.stop();
		
		try { 
			Thread.sleep(2000L); 
		} catch (Exception e) {
			
		}		
	}

}

@@ -156,16 +156,18 @@
 tener;%0A%0A
+//
 import o
@@ -191,16 +191,18 @@
 ctory;%0A%0A
+//
 import c
@@ -970,16 +970,19 @@
 ggers%0A%09%09
+// 
 LoggerCo
@@ -1045,16 +1045,19 @@
 ry();%0A%09%09
+// 
 lc.stop(

Modify ContextFinalizer