Java Servlet API allows to plug into the request lifecycle via the ServletRequestListener
class, which exposes callbacks for the following events:
- requestInitialized
- requestDestroyed
However, for the case I'm currently investigating, I need to differentiate between the moment a response is sent and the moment the request gets destroyed, in order to trace the cause of increased latency.
Is there such a way?
For further context, my app is built upon Spring Rest MVC for creating the endpoints and there is a significant difference (minutes even) between the moment the execution exits the controller and the moment the request gets destroyed. We have no postprocessing interceptors, so it isn't quite clear to me at which point the latency appears.