Author: markt Date: Fri Apr 1 14:24:43 2011 New Revision: 1087715 URL: http://svn.apache.org/viewvc?rev=1087715&view=rev Log: Workaround shutdown issue in unit tests
Modified: tomcat/trunk/java/org/apache/catalina/core/StandardContext.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/catalina/core/StandardContext.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardContext.java?rev=1087715&r1=1087714&r2=1087715&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/core/StandardContext.java (original) +++ tomcat/trunk/java/org/apache/catalina/core/StandardContext.java Fri Apr 1 14:24:43 2011 @@ -5414,14 +5414,21 @@ public class StandardContext extends Con // we do it in a dedicated thread for memory leak protection, in // case some webapp code registers some ThreadLocals that they // forget to cleanup - DedicatedThreadExecutor.executeInOwnThread( - new Callable<Void>() { + // TODO Figure out why DedicatedThreadExecutor hangs randomly in the + // unit tests if used here + RunnableWithLifecycleException stop = + new RunnableWithLifecycleException() { @Override - public Void call() throws Exception { + public void run() { ClassLoader old = bindThread(); try { for (int i = 0; i < children.length; i++) { - children[i].stop(); + try { + children[i].stop(); + } catch (LifecycleException e) { + le = e; + return; + } } // Stop our filters @@ -5430,19 +5437,35 @@ public class StandardContext extends Con // Stop ContainerBackgroundProcessor thread threadStop(); - if ((manager != null) && - (manager instanceof Lifecycle)) { - ((Lifecycle) manager).stop(); + if (manager != null && manager instanceof Lifecycle) { + try { + ((Lifecycle) manager).stop(); + } catch (LifecycleException e) { + le = e; + return; + } } // Stop our application listeners listenerStop(); - return null; }finally{ unbindThread(old); } } - }); + }; + + Thread t = new Thread(stop); + t.setName("stop children - " + getObjectName().toString()); + t.run(); + try { + t.join(); + } catch (InterruptedException e) { + // Shouldn't happen + throw new LifecycleException(e); + } + if (stop.getLifecycleException() != null) { + throw stop.getLifecycleException(); + } // Finalize our character set mapper setCharsetMapper(null); @@ -6492,4 +6515,13 @@ public class StandardContext extends Con return false; } + private abstract static class RunnableWithLifecycleException + implements Runnable { + + protected LifecycleException le = null; + + public LifecycleException getLifecycleException() { + return le; + } + } } Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1087715&r1=1087714&r2=1087715&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Fri Apr 1 14:24:43 2011 @@ -151,6 +151,10 @@ Provide additional configuration options for the DIGEST authenticator. (markt) </add> + <fix> + Provide a workaround for Tomcat hanging during shutdown when running the + unit tests. (markt) + </fix> </changelog> </subsection> <subsection name="Coyote"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org