title: Servlet initialized multiple times
body: <p>We are deploying a IIS site including several folders, a few virtual directories, and a Tomcat host.<br>
  When running Tomcat 8 (8.0.46) on Java 8, everything is fine.
  After upgrading to JDK 9 (OpenJDK 64-Bit Server VM (build 9.0.4+11, mixed mode)), we notice that each servlet is initialized several times (i.e. the method init(ServletConfig) is executed several times), the first time on the host context (as expected), and alter once for each folder in the site.<br>
  The undesired side-effect is that temporary files/logs created by the servlets are duplicated inside each folder in the site.<br></p>
  <p>Tomcat server.xml contains the Host definition:</p>
  <pre><code>      &lt;Host name=&quot;localhost&quot; appBase=&quot;C:/Program Files (x86)/b4/Controller/bin/webserver/ebsc_web&quot;
              unpackWARs=&quot;true&quot; autoDeploy=&quot;true&quot;&gt;
  
          &lt;Context path=&quot;/servlets&quot; docBase=&quot;C:/Program Files (x86)/b4/Controller/bin/webserver\ebsc_web\&quot;  xmlValidation=&quot;false&quot; xmlNamespaceAware=&quot;false&quot;&gt;
              &lt;WatchedResource&gt;WEB-INF/web.xml&lt;/WatchedResource&gt;
          &lt;/Context&gt;
  
          &lt;!--
          &lt;Valve className=&quot;org.apache.catalina.authenticator.SingleSignOn&quot; /&gt;
          --&gt;
  
          &lt;!-- Access log processes all example.
               Documentation at: /docs/config/valve.html
               Note: The pattern used is equivalent to using pattern=&quot;common&quot; --&gt;
          &lt;Valve className=&quot;org.apache.catalina.valves.AccessLogValve&quot; directory=&quot;logs&quot;
                 prefix=&quot;localhost_access_log&quot; suffix=&quot;.txt&quot;
                 pattern=&quot;%h %l %u %t &amp;quot;%r&amp;quot; %s %b&quot; /&gt;
        &lt;/Host&gt;
  </code></pre>
  <p>The same location (C:\Program Files (x86)\b4\Controller\bin\webserver\ebsc_web) is the physical path of the Web site, and includes subfolders, e.g.: applets, images, etc. When starting Tomcat logs are created at the default location (ebsc_web) and duplicated inside each subfolder.<br></p>
  <p>We noticed that when the servlet is initialized on the correct servlet context, the stack is:</p>
  <pre><code>Daemon Thread [localhost-startStop-1] (Suspended (breakpoint at line 49 in UpdateSchedulerLoader))  
      owns: StandardWrapper  (id=63)  
      owns: StandardContext  (id=64)  
      UpdateSchedulerLoader.init(ServletConfig) line: 49  
      StandardWrapper.initServlet(Servlet) line: 1227 
      StandardWrapper.loadServlet() line: 1140    
      StandardWrapper.load() line: 1027   
      StandardContext.loadOnStartup(Container[]) line: 5038   
      StandardContext.startInternal() line: 5348  
      StandardContext(LifecycleBase).start() line: 145    
      ContainerBase$StartChild.call() line: 1408  
      ContainerBase$StartChild.call() line: 1398  
      FutureTask&lt;V&gt;.run() line: 264   
      ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker) line: 1167  
      ThreadPoolExecutor$Worker.run() line: 641   
      Thread.run() line: 844  
  </code></pre>
  <p>but any following time when it is initialized with a servlet context pointing to a subfolder, the stack is:</p>
  <pre><code>Daemon Thread [localhost-startStop-1] (Suspended (breakpoint at line 42 in UpdateSchedulerLoader))  
      owns: StandardWrapper  (id=154) 
      owns: StandardContext  (id=144) 
      UpdateSchedulerLoader.init(ServletConfig) line: 42  
      StandardWrapper.initServlet(Servlet) line: 1227 
      StandardWrapper.loadServlet() line: 1140    
      StandardWrapper.load() line: 1027   
      StandardContext.loadOnStartup(Container[]) line: 5038   
      StandardContext.startInternal() line: 5348  
      StandardContext(LifecycleBase).start() line: 145    
      StandardHost(ContainerBase).addChildInternal(Container) line: 753   
      StandardHost(ContainerBase).addChild(Container) line: 729   
      StandardHost.addChild(Container) line: 717  
      HostConfig.deployDirectory(ContextName, File) line: 1129    
      HostConfig$DeployDirectory.run() line: 1871 
      Executors$RunnableAdapter&lt;T&gt;.call() line: 514   
      FutureTask&lt;V&gt;.run() line: 264   
      ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker) line: 1167  
      ThreadPoolExecutor$Worker.run() line: 641   
      Thread.run() line: 844  
  </code></pre>
  <p>So the first time the servlet is initialized by <code>ContainerBase$StartChild.call()</code>, later by <code>HostConfig.deployDirectory(ContextName, File)</code>...</p>
  <p>Can you explain/fix this behavior?</p>