Issue
We are deploying a IIS site including several folders, a few virtual directories, and a Tomcat host.
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.
The undesired side-effect is that temporary files/logs created by the servlets are duplicated inside each folder in the site.
Tomcat server.xml contains the Host definition:
<Host name="localhost" appBase="C:/Program Files (x86)/b4/Controller/bin/webserver/ebsc_web"
unpackWARs="true" autoDeploy="true">
<Context path="/servlets" docBase="C:/Program Files (x86)/b4/Controller/bin/webserver\ebsc_web\" xmlValidation="false" xmlNamespaceAware="false">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
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.
We noticed that when the servlet is initialized on the correct servlet context, the stack is:
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<V>.run() line: 264
ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker) line: 1167
ThreadPoolExecutor$Worker.run() line: 641
Thread.run() line: 844
but any following time when it is initialized with a servlet context pointing to a subfolder, the stack is:
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<T>.call() line: 514
FutureTask<V>.run() line: 264
ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker) line: 1167
ThreadPoolExecutor$Worker.run() line: 641
Thread.run() line: 844
So the first time the servlet is initialized by ContainerBase$StartChild.call()
, later by HostConfig.deployDirectory(ContextName, File)
...
Can you explain/fix this behavior?
Solution
The issue is solved, according to indication by @PiotrP.Karwasz, by setting both autoDeploy="false" deployOnStartup="false"
in Host configuration in server.xml.
Answered By - Marco Roda