From: markt Date: Fri, 1 Apr 2011 14:24:43 +0000 (+0000) Subject: Workaround shutdown issue in unit tests X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=15544280b75c56fba5d85dec48298ad1ca0fce76;p=tomcat7.0 Workaround shutdown issue in unit tests git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1087715 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/core/StandardContext.java b/java/org/apache/catalina/core/StandardContext.java index 9ec970eab..ed9869e41 100644 --- a/java/org/apache/catalina/core/StandardContext.java +++ b/java/org/apache/catalina/core/StandardContext.java @@ -5414,14 +5414,21 @@ public class StandardContext extends ContainerBase // 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() { + // 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 ContainerBase // 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 ContainerBase return false; } + private abstract static class RunnableWithLifecycleException + implements Runnable { + + protected LifecycleException le = null; + + public LifecycleException getLifecycleException() { + return le; + } + } } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 00d62a891..53dc6241b 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -151,6 +151,10 @@ Provide additional configuration options for the DIGEST authenticator. (markt) + + Provide a workaround for Tomcat hanging during shutdown when running the + unit tests. (markt) +