Supplement · Tomcat

Dispatch, Filter chain và asynchronous processing

Một request có thể qua nhiều dispatch type và nhiều thread; thread-local assumptions và completion ownership phải theo Servlet lifecycle.

Servlet

Servlet lifecycle

Container instantiate/init một Servlet rồi gọi service đồng thời từ nhiều request; instance fields không phải request-local. Destroy là cơ hội cleanup nhưng process crash/KILL không bảo đảm chạy. Filter ordering và dispatcher types quyết định security/tracing behavior.

Dispatch và errors

REQUEST, FORWARD, INCLUDE, ERROR và ASYNC có thể re-enter filters theo mapping. Response commit làm giới hạn khả năng đổi status/header. Error page không nên tiết lộ stack/config và phải tránh loop khi chính handler thất bại.

AsyncContext

startAsync release container request thread nhưng request vẫn in-flight, giữ connection/context và cần complete/dispatch/error/timeout. Async không tự biến blocking downstream thành nonblocking; custom executor cũng cần bound, context propagation và shutdown.

Observability

Trace cần survive dispatch/thread switch; access log completion time phải phản ánh async completion. Test timeout race, client disconnect, double complete, redeploy và graceful shutdown dưới async work.

Jakarta Servlet 6.0 · Tomcat Servlet API
← CoyoteCapacity →