Workers and sockets

  • Sample server.xml, default limits, OS backlog versus task queue, shared Executor configuration and saturation behavior.
100%
Socket entryTomcatDistinguish accepted sockets from worker tasksRequest / responseFailure / rejectionTCP acceptanceacceptrequest taskworker availablequeue / task rejectionsocket constraintDifferent requests can share the application connector/pipeline. A business route does not call the health route as a required next step.ClientacceptCount describes the backlog of pending acceptance when the acceptance boundary is constrained. Accepted socket accounting belongs to the connector; backlog is not a business-request or active-worker allowance.Accept backlogmaxConnections limits accepted sockets, not business requests, especially with keep-alive or multiplexing. Accepted sockets and worker request-dispatch tasks have different lifetimes. ConnectorWorker capacity is separate from socket count, queue size and Valve permits. A bypass does not reserve any of these resources. WorkerThe platform-thread executor has a task queue even when maxQueueSize is omitted; the Tomcat 9.0.122 default is Integer.MAX_VALUE. Choose a practical queue bound deliberately. With an attached Executor, its settings own the queue and workers.Task queueConnector/executor overflow can close a connection instead of returning a clean application 503. Observe the actual rejection boundary, not just the final status.OverflowTCP acceptanceacceptrequest taskworker availablequeue / task rejectionsocket constraint

Select a component to trace its direct connections. Drag to pan · Ctrl + wheel or pinch to zoom.

  • The accept backlog holds incoming connections until Tomcat accepts them. After acceptance, the connector submits processing tasks to an executor. A queued task waits for a worker.
  • An idle keep-alive connection can occupy a connection slot while using no request worker. Raising the accepted-connection limit alone therefore gives a saturated request pool no extra execution capacity.
Workers, queues and sockets

Workers, queues and sockets

Tomcat 9.0.122 · NIO and platform threads

Start with server.xml

This minimal standalone Tomcat 9.0.122 example deliberately omits worker, connection and queue limits. They still exist. It selects the NIO connector and its ordinary platform-thread executor; embedded frameworks, custom executors and virtual-thread configurations can differ. Keep the rest of your installation’s configuration when adapting it.

Minimal server.xml — omitted limits still applyxml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Teaching example: standalone Tomcat 9.0.122, NIO, platform threads.
     Keep the listeners, realms, resources and Hosts required by your installation.
     This is not a replacement production server.xml. -->
<Server port="-1">
  <Service name="Catalina">
    <Connector port="8080"
               protocol="org.apache.coyote.http11.Http11NioProtocol"
               connectionTimeout="20000" />
    <Engine name="Catalina" defaultHost="localhost">
      <Host name="localhost" appBase="webapps" />
    </Engine>
  </Service>
</Server>

What omission actually means

With no named executor, this Connector creates a private pool and task queue. Omitted attributes use these implementation defaults:

Setting Default Counts or controls
maxThreads 200 Worker threads in the internal pool
minSpareThreads 10 Core worker count; active plus idle
maxQueueSize 2,147,483,647 Runnable tasks waiting for workers
maxConnections 8,192 Connector connections
acceptCount 100 Requested OS listen backlog

Integer.MAX_VALUE is a queue capacity, not a preallocation of billions of tasks. In practice it is not a useful small overload bound: memory or caller deadlines can be exhausted much earlier. See the Connector reference and version-pinned executor construction.

Accept backlog: before Tomcat owns the socket

The listening socket has an OS-managed backlog even without an acceptCount attribute. Tomcat passes the requested backlog at socket bind; the OS can cap or interpret it differently. It is not a queue of parsed HTTP requests.

The acceptor checks connection capacity before accepting another socket. When acceptance cannot keep up, connections can wait in the kernel; a full backlog may produce connection failure or timeout. Saturating workers alone does not mean maxConnections has been reached.

The diagram condenses socket acceptance and task dispatch. It does not mean that every request must wait in both queues.

Task queue: accepted work waiting for a worker

After acceptance, NIO uses a poller to observe socket readiness and submits processing tasks to the executor. Idle keep-alive sockets do not each occupy a request worker. This task queue contains Runnable work inside the JVM; it is separate from the kernel backlog.

Tomcat’s TaskQueue lets available workers take tasks and encourages pool growth up to maxThreads under demand. Once all workers are occupied at that limit, further submitted tasks wait in the queue. A bounded queue can reject when it cannot accept more work.

For example, 80 busy workers and 120 waiting tasks describes two states of one illustrative pool. It is not a promise of 200 simultaneous business operations: socket events, redispatch and asynchronous application work have different lifetimes. A bounded queue does not cancel tasks whose callers have already timed out.

Choose who owns the limits

For a private pool, set maxThreads, minSpareThreads and maxQueueSize on the Connector. For a named shared Executor, put them on the Executor and reference its name from each participating Connector. Declare it before those Connectors.

The fragment below chooses 80 workers and 120 queued tasks for illustration. Those are shared across all Connectors referencing httpWorkers; each Connector still owns its own maxConnections and acceptCount. Connector thread settings do not create a second pool or a per-Connector share.

An otherwise unspecified StandardThreadExecutor defaults to 200 maximum workers, 25 core workers and Integer.MAX_VALUE queued tasks. Its core default differs from the private pool’s 10. A separate pool can isolate worker availability, but not JVM CPU, heap or downstream resources.

Alternative Service fragment — bounded shared Executorxml
<!-- Alternative fragment INSIDE the existing <Service> in server.xml.
     Declare the Executor BEFORE Connectors that reference it.
     Replace the original 8080 Connector; do not add another on the same port.
     All capacities below are illustrative, not Tomcat defaults or sizing advice. -->
<Executor name="httpWorkers"
          className="org.apache.catalina.core.StandardThreadExecutor"
          namePrefix="http-worker-"
          maxThreads="80"
          minSpareThreads="10"
          maxQueueSize="120" />

<Connector port="8080"
           protocol="org.apache.coyote.http11.Http11NioProtocol"
           executor="httpWorkers"
           maxConnections="1000"
           acceptCount="100"
           connectionTimeout="20000" />

<!-- Keep the existing Engine and Host below these elements.
     Another Connector referencing httpWorkers shares the SAME 80 workers
     and 120 queued-task slots, but keeps its own socket/backlog settings. -->

What the caller sees under saturation

Saturated boundary Possible observation
OS backlog / acceptance Slow connection establishment, refusal or timeout
Worker pool with queue space Connection exists, but processing waits
Full executor task queue Task rejection; the socket may be closed
Application admission Valve Explicit HTTP rejection if configured

Executor rejection happens before the application can necessarily send a response; it does not guarantee a clean HTTP 503. In the NIO path, unsuccessful task submission can lead to socket closure.

Treat those observations as diagnostic clues, not unique signatures. Check the effective Connector/Executor configuration, current busy workers, connection count, task backlog and errors together. Increasing every queue can retain more work while worsening latency; a business concurrency gate and deadline policy solve different problems.

Timeouts and the configuration you actually run

The first example explicitly uses connectionTimeout="20000". This is also the value in the shipped 9.0.122 server.xml; the Connector attribute’s documented default when omitted is 60000 ms. A sample-file setting and an implementation default are different things.

connectionTimeout governs waits for the request line and, with the default upload-timeout behavior, request-body reads. It is not a 20-second deadline for the whole business operation. keepAliveTimeout, servlet asynchronous timeouts and outbound HTTP/DB deadlines have separate scopes.

Use the effective configuration and startup diagnostics from the actual Tomcat version before sizing it. The XML here is explanatory; it has not changed any running server.