1

I have a spring controller and request mapped method.

@RequestMapping(value = { "/doSomething.do" })
public ModelAndView emailToNonBelievers(){
    .....
    // do something which takes lot of time 

    // send response..
    return modelAndView;

}

This method takes very long time, about an hour.(It is for Admin, not users. And Admin doesn't need to wait an hour. Just fire and forget, that's ok. And this is not a batch job)

But I found that client send requests repeatedly with 3 minutes interval(observed 6 times and I stopeed Spring service).

I guess because client didn't get any response from server.

If my guess is right, server should response sort of "Your request is accepted, just shut up and wait!!" .

But how to send response(200 ok) before jobs finished in Spring?

Or am I missing something?

Deckard
  • 1,409
  • 6
  • 32
  • 59

1 Answers1

1

In this situation it would be recommended to use asynchronous task processing.

Spring comes with out-of-box support for it via @Async annotation.

Consult my answer for detailed setup for similar query and here for docs.

Community
  • 1
  • 1
Bond - Java Bond
  • 3,972
  • 6
  • 36
  • 59