Execution overview

  • Connect socket acceptance, worker tasks, Valve permits and asynchronous completion.
100%
Socket entryTomcatAll Tomcat execution boundariesRequest / responseHealth checksControl / stateFailure / rejectionTCP acceptanceacceptrequest taskworker availablequeue / task rejectionsocket constraintpipeline scopeordinary requestselected bypassno permitadmittedbusiness routehealth routeinvocation returnhandler returnrelease stock permitasync continuationactual completionrelease at actual endretain accountingseparate limitsDifferent 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. ConnectorThe 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 queueWorker capacity is separate from socket count, queue size and Valve permits. A bypass does not reserve any of these resources. WorkerOne installed instance supplies one permit budget at its selected application scope. This illustrative nonblocking profile uses block=false; identical separate instances do not share permits.Admission ValveConnector/executor overflow can close a connection instead of returning a clean application 503. Observe the actual rejection boundary, not just the final status.OverflowThe selected bypass stays inside the application JVM and needs its own bounded execution/access contract. It still relies on connector workers and CPU unless independence is deliberately implemented. Management requestStock SemaphoreValve has no configured URL-exclusion list. A deliberate pipeline placement/controlConcurrency hook supplies only the intended trusted bypass. Ordinary readiness remains gated.Bypass policyIn the chosen block=false profile, unavailable permits reject immediately. This does not cancel work already admitted or create new execution capacity.Local rejectionIf a full logical/async lifetime cap is needed, implement it separately from the stock invocation permit. Keep retained work accounted until actual completion/cancellation.Logical accountingStock SemaphoreValve releases its permit when the downstream invocation returns. That return does not prove asynchronously dispatched provider work completed. Invocation returnDispatch selects the requested business operation. It shares execution resources with eligible health requests, without calling the health route implicitly. Business routeBusiness and health are independent dispatch alternatives. Sharing a pipeline or gate is not a route-to-route call.Route dispatchAsync work may survive the servlet/Valve return and caller waiting. Cancellation acknowledgement or a returned Future is not actual I/O termination. Async workRelease its resources and completion-aware logical accounting when actual work ends. Cover exceptional/cancellation callbacks and context restoration. Actual completionThe configured health operation executes its own selected checks. It does not exercise every business route or real provider merely because it shares the JVM. Health routeSocket, task queue, worker and invocation-permit limits are typed budgets. Readiness/liveness sampling and business deadlines are additional contracts, not substitutes for those budgets. Separate budgetsTCP acceptanceacceptrequest taskworker availablequeue / task rejectionsocket constraintpipeline scopeordinary requestselected bypassno permitadmittedbusiness routehealth routeinvocation returnhandler returnrelease stock permitasync continuationactual completionrelease at actual endretain accountingseparate limits

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

  • Follow one request from an accepted socket to a connector task, an executor worker and the application’s Valve. The socket, worker and admission permit each have a different lifetime.
  • For asynchronous servlet work, a worker and its invocation permit can become available while the operation is still running. Management traffic can also compete for shared connector resources.
Enable and use SemaphoreValve

Enable and use SemaphoreValve

Tomcat 9.0.122 · SemaphoreValve

Choose the scope

Use Context for one application, Host for its applications, or Engine for the engine scope.

Each installed Valve has its own permit budget. Separate instances do not share one allowance.

Install the XML

For one application, add the Valve to its existing Context in CATALINA_BASE/conf/Catalina/localhost/APP.xml.

Keep existing Context attributes. APP is a placeholder; concurrency=64 is illustrative.

Application Context XMLxml
<Context>
  <Valve className="org.apache.catalina.valves.SemaphoreValve"
         concurrency="64"
         block="false"
         highConcurrencyStatus="503" />
</Context>

Set rejection

block=false refuses excess invocations immediately. The default true can wait.

highConcurrencyStatus=503 sends an error response. Default -1 sends no error; refused work does not enter the downstream pipeline.

Activate and verify

Use controlled application redeploy or Tomcat restart, following the target deployment settings.

Manager reload retains the Context and does not reliably install a Valve from changed Context XML. Check actual placement and the rejection response after activation.

Lifetime and bypass

The permit ends when downstream invocation returns; asynchronous work may continue. Cap full logical work with separate completion-aware accounting.

Stock SemaphoreValve has no URL-exclusion list. Use deliberate pipeline placement or controlConcurrency for a selected bypass; permitDenied controls denial.

A bypass reserves no CPU, sockets or workers.

Context XML activation: automatic deployment, modified files. The installed target version and its deployment settings still need checking.

Servlet dispatch

Servlet dispatch

  • Business and health routes can be independent dispatch alternatives through a shared connector and application pipeline.
  • Sharing a runtime resource does not make one route call another route.
Management execution

Management execution

  • Stock SemaphoreValve has no configurable URL-exclusion list; its extension hook or deliberate pipeline placement supplies a selected bypass.
  • A bypass does not reserve CPU or connector workers. Diagnostic execution still needs bounded resources and access controls.