java - Spring Controller start processing after response is sent -
i using spring mvc controller , want start execution of task new thread. thread should not start after response has been sent client.
means - in strict temporal order:
- request
- return new responseentity ... / client receives http status 200 ok.
- processing of task begins.
how achieve ?
i wanted use spring's async abstraction, calling method annotated @async, way have not guarantee new thread waits response sent.
you can use interceptor that. order or events handling request in spring mvc :
- dispatcherservlet request, response pair , determines handling
- [optional] interceptors prehandle called (with option stop processing)
- controller called
- [optional] interceptors posthandle called
- viewresolver , view actual response processing , send response
- [optional] interceptors aftercompletion called
the above on simplificated , aimed @ showing interceptor aftercompletion methods called after response has been sended client, following signature :
void aftercompletion(httpservletrequest request, httpservletresponse response, object handler, exception ex) throws exception
in method, can test occurence of exception , correctness of response (ex == null && response.getstatus == httpservletresponse.sc_ok
) before starting processing.
Comments
Post a Comment