Author: markt Date: Tue Apr 22 08:31:56 2014 New Revision: 1589043 URL: http://svn.apache.org/r1589043 Log: Refactor server container shutdown into the destroy method Destroy the thread group on shutdown Log a warning if the thread group can't be destroyed
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties tomcat/trunk/java/org/apache/tomcat/websocket/server/WsContextListener.java tomcat/trunk/java/org/apache/tomcat/websocket/server/WsServerContainer.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties?rev=1589043&r1=1589042&r2=1589043&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties (original) +++ tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties Tue Apr 22 08:31:56 2014 @@ -22,6 +22,7 @@ serverContainer.missingEndpoint=An Endpo serverContainer.pojoDeploy=POJO class [{0}] deploying to path [{1}] in ServletContext [{2}] serverContainer.servletContextMismatch=Attempted to register a POJO annotated for WebSocket at path [{0}] in the ServletContext with context path [{1}] when the WebSocket ServerContainer is allocated to the ServletContext with context path [{2}] serverContainer.servletContextMissing=No ServletContext was specified +serverContainer.threadGroupNotDestroyed=Unable to destroy WebSocket thread group [{0}] as some threads were still running when the web application was stopped uriTemplate.duplicateParameter=The parameter [{0}] appears more than once in the path which is not permitted uriTemplate.emptySegment=The path [{0}] contains one or more empty segments which are is not permitted Modified: tomcat/trunk/java/org/apache/tomcat/websocket/server/WsContextListener.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/WsContextListener.java?rev=1589043&r1=1589042&r2=1589043&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/websocket/server/WsContextListener.java (original) +++ tomcat/trunk/java/org/apache/tomcat/websocket/server/WsContextListener.java Tue Apr 22 08:31:56 2014 @@ -45,7 +45,6 @@ public class WsContextListener implement ServletContext sc = sce.getServletContext(); Object obj = sc.getAttribute(Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE); if (obj instanceof WsServerContainer) { - ((WsServerContainer) obj).shutdownExecutor(); ((WsServerContainer) obj).destroy(); } } Modified: tomcat/trunk/java/org/apache/tomcat/websocket/server/WsServerContainer.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/WsServerContainer.java?rev=1589043&r1=1589042&r2=1589043&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/websocket/server/WsServerContainer.java (original) +++ tomcat/trunk/java/org/apache/tomcat/websocket/server/WsServerContainer.java Tue Apr 22 08:31:56 2014 @@ -49,6 +49,8 @@ import javax.websocket.server.ServerEndp import javax.websocket.server.ServerEndpointConfig; import javax.websocket.server.ServerEndpointConfig.Configurator; +import org.apache.juli.logging.Log; +import org.apache.juli.logging.LogFactory; import org.apache.tomcat.util.res.StringManager; import org.apache.tomcat.websocket.WsSession; import org.apache.tomcat.websocket.WsWebSocketContainer; @@ -70,6 +72,8 @@ public class WsServerContainer extends W private static final StringManager sm = StringManager.getManager(Constants.PACKAGE_NAME); + private static final Log log = LogFactory.getLog(WsServerContainer.class); + private static final CloseReason AUTHENTICATED_HTTP_SESSION_CLOSED = new CloseReason(CloseCodes.VIOLATED_POLICY, "This connection was established under an authenticated " + @@ -88,6 +92,7 @@ public class WsServerContainer extends W private final ConcurrentHashMap<String,Set<WsSession>> authenticatedSessions = new ConcurrentHashMap<>(); private final ExecutorService executorService; + private final ThreadGroup threadGroup; private volatile boolean endpointsRegistered = false; WsServerContainer(ServletContext servletContext) { @@ -152,7 +157,7 @@ public class WsServerContainer extends W } else { threadGroupName.append(servletContext.getContextPath()); } - ThreadGroup threadGroup = new ThreadGroup(threadGroupName.toString()); + threadGroup = new ThreadGroup(threadGroupName.toString()); WsThreadFactory wsThreadFactory = new WsThreadFactory(threadGroup); executorService = new ThreadPoolExecutor(executorCoreSize, @@ -270,6 +275,21 @@ public class WsServerContainer extends W } + @Override + public void destroy() { + shutdownExecutor(); + super.destroy(); + try { + threadGroup.destroy(); + } catch (IllegalThreadStateException itse) { + // If the executor hasn't fully shutdown it won't be possible to + // destroy this thread group as there will still be threads running + log.warn(sm.getString("serverContainer.threadGroupNotDestroyed", + threadGroup.getName())); + } + } + + boolean areEndpointsRegistered() { return endpointsRegistered; } @@ -439,7 +459,7 @@ public class WsServerContainer extends W } - void shutdownExecutor() { + private void shutdownExecutor() { if (executorService == null) { return; } Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1589043&r1=1589042&r2=1589043&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Tue Apr 22 08:31:56 2014 @@ -213,6 +213,11 @@ implementation for call backs associated with asynchronous writes from 10 to 200. (markt) </fix> + <add> + Add a warning if the thread group created for WebSocket asynchronous + write call backs can not be destroyed when the web application is + stopped. (markt) + </add> </changelog> </subsection> <subsection name="Web applications"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org