The effect you are describing is called request queuing. By default Tomcat starts and listens to its configured port. When the first request comes in, it triggers that the corresponding web application is deployed and started. All requests that come in before the application is started are blocked and processing starts when the application startup is done.
The above description is a little simplified, because depending on your Tomcat connector type and configuration there are different areas where requests can blocked and queued up:
- A processing thread waits for the application to start. The limit is controlled by
maxThreads
.
- A request waits for a processing thread. The limit is controlled by
maxConnections
.
- An incoming TCP connection is accepted by the operating system but not yet handled by Tomcat. This is controlled by
acceptCount
. (BTW: I set this to 0)
As said, how the parameters work in detail may vary by connector type.
This is how you can control the limits and for the understanding what is going on. I think your effect will get better with setting acceptCount to 0.
Actually, the same problem and question was asked in: how to make http port to open after application startup in tomcat No real answer there, also. It seams this is not how Tomcat is designed to work. Solutions I can think of, but not yet tried myself:
- Find a way to start Tomcat with a disabled connector (I found no parameter for that...) and enable it after startup by JMX
- Switch to an embedded Tomcat or Jetty, that gets started from the application