Skip to content

Commit

Permalink
Merge pull request zanata#388 from zanata/rhbz1074365
Browse files Browse the repository at this point in the history
rhbz1074365 Prevent thread leaks on redeploy
  • Loading branch information
djansen-redhat committed Mar 26, 2014
2 parents b5a6257 + ac00fcb commit 469fb24
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 10 deletions.
12 changes: 12 additions & 0 deletions zanata-war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2016,6 +2016,18 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>se.jiderhamn</groupId>
<artifactId>classloader-leak-prevention</artifactId>
<version>1.9.2</version>
<exclusions>
<exclusion>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- missing dependencies identified by mvn dependency:analyze: -->

<dependency>
Expand Down
59 changes: 59 additions & 0 deletions zanata-war/src/main/java/org/zanata/servlet/LeakListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2014, Red Hat, Inc. and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.zanata.servlet;

import java.util.logging.Level;

import lombok.extern.java.Log;
import se.jiderhamn.classloader.leak.prevention.ClassLoaderLeakPreventor;

/**
* @author Sean Flanigan <a href="mailto:[email protected]">[email protected]</a>
*
*/
@Log
public class LeakListener extends ClassLoaderLeakPreventor {
protected void debug(String s) {
log.fine(s);
}

protected void info(String s) {
log.info(s);
}

protected void warn(String s) {
log.warning(s);
}

protected void warn(Throwable t) {
log.log(Level.WARNING, "", t);
}

protected void error(String s) {
log.severe(s);
}

protected void error(Throwable t) {
log.log(Level.SEVERE, "", t);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@

import de.novanic.eventservice.service.registry.EventRegistry;
import de.novanic.eventservice.service.registry.EventRegistryFactory;
import de.novanic.eventservice.service.registry.user.UserManager;
import de.novanic.eventservice.service.registry.user.UserManagerFactory;

@Scope(ScopeType.APPLICATION)
@Name("translationWorkspaceManager")
Expand Down Expand Up @@ -103,13 +105,6 @@ ValidationService getValidationService() {
@Observer(ZanataInit.EVENT_Zanata_Startup)
public void start() {
log.info("starting...");

Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
stopListeners();
}
});
}

@Observer(ZanataIdentity.USER_LOGOUT_EVENT)
Expand Down Expand Up @@ -216,9 +211,7 @@ private boolean projectIterationIsActive(EntityStatus projectStatus,
public void stop() {
log.info("stopping...");
log.info("closing down {} workspaces: ", workspaceMap.size());
}

private void stopListeners() {
// Stopping the listeners frees up the EventServiceImpl servlet, which
// would otherwise prevent Apache Coyote from shutting down quickly.
// Note that the servlet may still hang around up to the max timeout
Expand All @@ -233,6 +226,9 @@ private void stopListeners() {
log.info(
"Removed {} client(s). Waiting for outstanding polls to time out...",
clientCount);
UserManager userManager =
UserManagerFactory.getInstance().getUserManager();
userManager.getUserActivityScheduler().stop();
}

@Override
Expand Down
8 changes: 7 additions & 1 deletion zanata-war/src/main/webapp-jboss/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@


<!--
Make sure Liquibase is the first listener, so that it can update the database schema before
Make sure Liquibase is the first listener (after ClassLoaderLeakPreventor),
so that it can update the database schema before
anyone uses the database.
-->

Expand Down Expand Up @@ -110,6 +111,11 @@
<param-value>java:jboss/datasources/${ds.jndi.name}</param-value>
</context-param>

<!-- ClassLoaderLeakPreventor needs to be first, so that it can stop all leaks -->
<listener>
<listener-class>org.zanata.servlet.LeakListener</listener-class>
</listener>

<listener>
<listener-class>liquibase.integration.servlet.LiquibaseServletListener</listener-class>
</listener>
Expand Down

0 comments on commit 469fb24

Please sign in to comment.