On this page
Short answer
Running Tomcat in production comes down to five settings you should choose on purpose: the connector thread pool (200 threads by default), the accept queue (100), the timeouts, the database pool behind the application, and where sessions live. Set each one from measured load, add a timeout to every outbound call, and keep a thread dump command ready.
Running Tomcat in production comes down to five settings you should choose on purpose: the connector thread pool (200 threads by default), the accept queue (100), the timeouts, the database pool behind the application, and where sessions live. Set each one from measured load, add a timeout to every outbound call, and keep a thread dump command ready.
The defaults below come from the Apache Tomcat 10.1 documentation. Tomcat 9.0 matches unless a section says otherwise. If a node is already hanging or failing, our tomcat consulting team starts from the same thread dump described in step 7.
What are the Tomcat connector defaults, and which ones matter?
The HTTP connector serves requests from one pool of up to 200 threads (maxThreads). When all threads are busy, Tomcat accepts connections until it reaches maxConnections (8192 for NIO and NIO2), and the operating system queues the overflow up to acceptCount (100).
| Setting | Default | What it controls |
|---|---|---|
maxThreads |
200 | Simultaneous requests processed |
minSpareThreads (Executor) |
25 | Threads always kept alive |
maxConnections |
8192 (NIO, NIO2) | Connections accepted while threads are busy |
acceptCount |
100 | OS queue once maxConnections is reached |
connectionTimeout |
60000 ms in the docs, 20000 ms in the shipped server.xml |
Wait for the request line after accept |
keepAliveTimeout |
Same as connectionTimeout |
Idle wait between requests on one connection |
maxKeepAliveRequests |
100 | Requests per keep-alive connection |
If you define an <Executor>, the connector ignores its own maxThreads and uses the executor's, which also defaults to 200.
What are the best practices for running Tomcat in a production environment?
These are the steps we check on a Tomcat server before it carries traffic for its web applications.
- Separate the install from the configuration.
RUNNING.txtrecommends settingCATALINA_HOMEexplicitly and using a differentCATALINA_BASEfor your configuration and web applications, withJAVA_HOME(orJRE_HOME) set to the Java you intend to run. - Define one shared Executor. Name it, set
maxThreadsfrom a load test andminSpareThreadsabove the 25 default if traffic arrives in bursts, and point every connector at it withexecutor="...". - Do not raise
maxThreadsto fix slowness. A larger pool only lets more requests wait on the same slow dependency. Raise it when threads are busy doing CPU or I/O work and the database can take the extra load. - Set the timeouts on purpose. The shipped
server.xmlalready setsconnectionTimeoutto 20000 ms, so check that your ownserver.xmlkept it. BecausekeepAliveTimeoutinherits it, a longconnectionTimeoutalso holds idle keep-alive connections open for a long time. - Size the database pool from measured concurrency. Apache Commons DBCP 2 defaults to
maxTotal8 andmaxWaitMillisof -1, which waits forever. A pool of 8 under 200 request threads means 192 threads can sit waiting. SetmaxWaitMillisto a few seconds so a pool problem becomes an error in the log, not a hang. - Add a stuck thread valve.
StuckThreadDetectionValvelogs requests running longer thanthreshold(600 seconds by default). Set it far lower than that, and note that its threshold should be higher than thebackgroundProcessorDelayof the container that declares it. - Keep a thread dump command ready. Run
jcmd <pid> Thread.print > dump.txtthree times, ten seconds apart. Thejcmddocumentation rates Thread.print as medium impact, depending on the number of threads, so take the dumps one at a time. - Disable what you do not use. Set the Server
portto -1 to disable the shutdown port (or set a strong shutdown password). Remove the AJP connector unless a proxy needs it, and give it asecretif you keep it. - Put JVM options in
setenv.sh.RUNNING.txtnames a setenv script ($CATALINA_BASE/bin/setenv.shon Linux) as the recommended place forCATALINA_OPTSand similar variables, and it is read only when you start Tomcat with the standard scripts.
How do I read a Tomcat thread dump?
Count the threads named http-nio-8080-exec-N (the name follows your connector port) and group them by the frame they are waiting in. If 190 of 200 wait in the same place, that place is your problem.
| Where the threads wait | Likely cause | First fix |
|---|---|---|
Pool borrowObject or getConnection |
Database pool too small or connections leaked | Set maxWaitMillis, check pool size and abandoned-connection settings |
SocketInputStream.read or similar |
Outbound HTTP call with no read timeout | Add connect and read timeouts to the client |
Object.wait on one lock |
Contended synchronized block in the application | Fix the code path, not the thread count |
Few exec threads, mostly idle |
Problem is upstream of Tomcat | Check the proxy, load balancer and DNS |
What happens to sessions when Tomcat restarts?
It depends on the version. In Tomcat 9.0 the standard Manager's pathname defaults to SESSIONS.ser, so sessions are written to that file on a clean shutdown and read back on startup. In Tomcat 10.1 the pathname default is null, so sessions are not preserved across a restart unless you set it. Check this before you move a 9.0 application to 10.1, because users who stayed logged in through restarts will start being logged out.
For failover rather than restarts, you need replication, an external session store, or sticky routing at the load balancer. PersistentManager can swap idle sessions out to a file or database store. maxActiveSessions defaults to -1 (no limit), so cap it if memory is tight.
How do I run Tomcat in a container?
Size the JVM against the container limit, not the host, and leave room above the heap for Metaspace, thread stacks and direct buffers. Set a readiness probe that checks an application URL, not just the port.
For redeploy leaks, clearReferencesThreadLocals is already true by default, and clearReferencesRmiTargets needs an extra JVM option, so the usual fix is in the application or the library that holds the reference, not in Tomcat. If you want a second pair of eyes on any of this, ask a tomcat consultant to review your server.xml, executor and pool settings against a real thread dump.
Sources
- tomcat.apache.org/tomcat-10.1-doc/config/http.html
- tomcat.apache.org/tomcat-10.1-doc/config/executor.html
- tomcat.apache.org/tomcat-10.1-doc/config/valve.html
- tomcat.apache.org/tomcat-10.1-doc/RUNNING.txt
- tomcat.apache.org/tomcat-10.1-doc/config/manager.html
- tomcat.apache.org/tomcat-9.0-doc/config/manager.html
- commons.apache.org/proper/commons-dbcp/configuration.html
- docs.oracle.com/en/java/javase/21/docs/specs/man/jcmd.html
Frequently Asked Questions
What is the default maxThreads in Tomcat?
200 for the HTTP connector, or the Executor's own `maxThreads` (also 200) if the connector uses a shared Executor. The `acceptCount` queue defaults to 100 and `maxConnections` to 8192 for NIO and NIO2.
Why is Tomcat slow when CPU is idle?
Request threads are usually waiting on something outside Tomcat, most often a database pool or an outbound call with no timeout. Take three thread dumps with `jcmd <pid> Thread.print` and look for many `exec` threads waiting in the same frame.
Does Tomcat keep sessions after a restart?
Tomcat 9.0 saves them to `SESSIONS.ser` by default on a clean shutdown. Tomcat 10.1 does not unless you set the Manager `pathname`. Neither helps after a crash or when a load balancer moves users to another node.
Talk to an engineer
Need a hand with Tomcat?
Senior engineers who run it in production. Get a quote or a free consultation, no sales pitch.

