BlogTomcat

Tomcat Requests Hang With Idle CPU: Thread Dump Guide

Scott Sternloff

By Scott Sternloff, Senior Enterprise Architect

LinkedIn · Updated · 5 min read

Tomcat Requests Hang With Idle CPU: Thread Dump Guide
On this page

Short answer

When Tomcat requests hang while CPU stays idle, the request threads are waiting, not working. The usual cause is every thread in the pool (200 by default) blocked on a database pool or an outbound call with no timeout. Take three thread dumps ten seconds apart and group the exec threads by the frame they wait in.

When Tomcat requests hang while CPU stays idle, the request threads are waiting, not working. The usual cause is every thread in the pool (200 by default) blocked on a database pool or an outbound call with no timeout. Take three thread dumps ten seconds apart and group the exec threads by the frame they wait in.

This guide goes past the connector defaults covered in our how to run Tomcat in production post and into diagnosis. If a node is hung now, our Tomcat consulting engineers start from the same three dumps, and the steps below use Tomcat 10.1 behaviour.

Why does Tomcat hang when CPU is idle?

Because each non-asynchronous request holds one thread for its whole duration, so a few slow dependencies can occupy every thread while using almost no CPU. New requests then wait in the connection queues, and the application looks frozen. From outside it appears as timeouts, or as a 503 from the proxy in front, while the server shows low CPU usage.

Tomcat applies its limits in order. The table shows what each one looks like during a hang.

LimitDefault (10.1 docs)What it looks like when full
maxThreads200Every exec thread busy; new requests wait
maxConnections8192 (NIO, NIO2)Tomcat accepts one more connection but does not process it
acceptCount100Operating system queue; beyond it, connections are refused or time out

How do I take a thread dump of a hung Tomcat?

Take three dumps about ten seconds apart, so you can tell a stuck thread from a slow one.

  1. List the JVMs with jcmd and note the Tomcat process ID.
  2. Run jcmd <pid> Thread.print -l > dump1.txt. The -l option adds java.util.concurrent lock information.
  3. Wait ten seconds and repeat for dump2 and dump3.
  4. Save the Tomcat log and the dumps together before you restart anything.
for i in 1 2 3; do jcmd <pid> Thread.print -l > dump$i.txt; sleep 10; done

Prefer jcmd to jstack: the JDK 21 manual calls jstack experimental and unsupported, and rates Thread.print impact as medium, depending on the number of threads.

What should I look for in the dumps?

Count the threads named http-nio-8080-exec-N (the number follows your connector port) and group them by the frame they wait in. A frame that holds most of the pool and is identical in all three dumps is your stall.

Where the exec threads waitLikely causeCheck next
Pool borrowObject or getConnectionDatabase pool exhausted or connections leakedPool size and wait limit
Socket read inside an HTTP clientOutbound call with no read timeoutClient connect and read timeouts
BLOCKED, waiting to lock the same monitorLock contention in application codeThe thread that holds the lock, in the same dump
Few exec threads, mostly idleThe wait is upstream of TomcatProxy, load balancer and DNS

If the same threads sit in the same frames across all three dumps they are stuck. If the frames change, the system is slow rather than hung, and the fix is capacity or a slow query.

How do I rule out garbage collection and the heap?

Read the dumps for state. Threads that are waiting on a pool, a socket or a lock point to a dependency. Threads that are RUNNABLE in application code, or a process that pauses as a whole, point to the JVM: check the garbage collection log for long pauses and compare heap use with the configured maximum.

A long garbage collection pause stops every request thread at once and shows in the GC log, not in the dumps, so keep the log next to the three dumps.

Which pool or timeout is usually behind the hang?

The database pool is the most common culprit, because its defaults favour waiting. The Apache Commons DBCP configuration page lists maxTotal as 8 and maxWaitMillis as indefinite, so 192 of 200 request threads can queue for 8 connections with no error. Set maxWaitMillis to a few seconds so an exhausted pool becomes a logged exception.

DBCP also ships with removeAbandonedOnBorrow and logAbandoned both false, so a leaked connection stays invisible until you turn them on.

Add StuckThreadDetectionValve to find the next stall without a manual dump. Its threshold defaults to 600 seconds, so lower it to a value just above your slowest legitimate request. The valve logs the stuck thread's stack at WARN and exposes stuckThreadIds and stuckThreadNames through JMX. interruptThreadThreshold is -1 by default; the docs say interrupting usually helps with threads blocked on I/O or locks but is probably useless for infinite loops.

How do I stop it coming back?

  • Put a connect and a read timeout on every outbound call. Tomcat cannot enforce them for your code.
  • Cap the wait on every pool. A pool error in the log beats a silent queue.
  • Leave maxThreads alone until the dumps show threads busy on CPU work. See the defaults in how to run Tomcat in production.
  • Keep the dump command in your runbook, with a person who knows how to read it.

AceMQ's senior engineers read dumps like these with your team, with 24/7 cover and response targets from 15 minutes, by plan. For a review of your executor and pool settings against real dumps, see our connector and thread pool review.

Sources

Frequently Asked Questions

Will a larger maxThreads fix a Tomcat hang?

Rarely. If the threads are waiting on a database pool or an outbound call, a bigger pool only queues more requests behind the same stall. Find what the threads wait on first, then size the pool.

Is it safe to take a thread dump of a production Tomcat?

Generally yes, with `jcmd <pid> Thread.print`. The JDK 21 documentation rates its impact as medium and dependent on the number of threads. It marks `jstack` as experimental and unsupported, so prefer `jcmd`.

What does Tomcat's StuckThreadDetectionValve do by default?

It writes the stack of any request running longer than 600 seconds to the log at WARN level. It does not interrupt the thread unless you set `interruptThreadThreshold`, which defaults to -1.

Scott Sternloff

Author

Scott SternloffSenior Enterprise Architect

Senior Enterprise Architect at AceMQ. Writes the technical coverage here: RabbitMQ, Kafka and Redis architecture, clustering and migrations.

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.

Free Consultation

Get Expert Eyes on Your Tomcat Environment

Whether you're troubleshooting a production incident, planning a migration, or want a second opinion on your architecture — our team is ready. No pitch, just answers.

Email Us