use of se.jiderhamn.classloader.leak.prevention.ClassLoaderLeakPreventor in project mycore by MyCoRe-Org.
the class MCRServletContainerInitializer method onStartup.
/* (non-Javadoc)
* @see javax.servlet.ServletContainerInitializer#onStartup(java.util.Set, javax.servlet.ServletContext)
*/
@Override
public void onStartup(final Set<Class<?>> c, final ServletContext ctx) throws ServletException {
ClassLoaderLeakPreventor leakPreventor = new MCRClassLoaderLeakPreventor();
leakPreventor.contextInitialized(new ServletContextEvent(ctx));
MCRShutdownHandler shutdownHandler = MCRShutdownHandler.getInstance();
shutdownHandler.isWebAppRunning = true;
shutdownHandler.leakPreventor = leakPreventor;
MCRStartupHandler.startUp(ctx);
// Make sure logging is configured
final Logger LOGGER = LogManager.getLogger();
if (LOGGER.isDebugEnabled()) {
try {
Enumeration<URL> resources = this.getClass().getClassLoader().getResources("META-INF/web-fragment.xml");
while (resources.hasMoreElements()) {
LOGGER.debug("Found: {}", resources.nextElement());
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
LOGGER.debug("This class is here: {}", getSource(this.getClass()));
}
}
use of se.jiderhamn.classloader.leak.prevention.ClassLoaderLeakPreventor in project mycore by MyCoRe-Org.
the class MCRShutdownHandler method shutDown.
void shutDown() {
Logger logger = LogManager.getLogger(MCRShutdownHandler.class);
String cfgSystemName = "MyCoRe:";
try {
cfgSystemName = MCRConfiguration.instance().getString(PROPERTY_SYSTEM_NAME) + ":";
} catch (MCRConfigurationException e) {
// may occur early if there is an error starting mycore up or in JUnit tests
logger.warn("Error getting '" + PROPERTY_SYSTEM_NAME + "': {}", e.getMessage());
}
final String system = cfgSystemName;
System.out.println(system + " Shutting down system, please wait...\n");
logger.debug(() -> "requests: " + requests);
Closeable[] closeables = requests.stream().toArray(Closeable[]::new);
Stream.of(closeables).peek(c -> logger.debug("Prepare Closing (1): {}", c)).forEach(Closeable::prepareClose);
shutdownLock.writeLock().lock();
try {
shuttingDown = true;
// during shut down more request may come in MCR-1726
requests.stream().filter(c -> !Arrays.asList(closeables).contains(c)).peek(c -> logger.debug("Prepare Closing (2): {}", c)).forEach(Closeable::prepareClose);
requests.stream().peek(c -> logger.debug("Closing: {}", c)).forEach(Closeable::close);
System.out.println(system + " closing any remaining MCRSession instances, please wait...\n");
MCRSessionMgr.close();
System.out.println(system + " Goodbye, and remember: \"Alles wird gut.\"\n");
LogManager.shutdown();
SINGLETON = null;
} finally {
shutdownLock.writeLock().unlock();
}
// may be needed in webapp to release file handles correctly.
if (leakPreventor != null) {
ClassLoaderLeakPreventor myLeakPreventor = leakPreventor;
leakPreventor = null;
myLeakPreventor.contextDestroyed(null);
}
}
Aggregations