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:

  1. request
  2. return new responseentity ... / client receives http status 200 ok.
  3. 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

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -