Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring boot - how to stop the backend rest api processing after the frontend is closed

Tags:

I'm using spring boot to create a restful backend application and the frontend is using vue. When someone sends a rest request to my backend application via my frontend webpage, is it possible to stop the backend processing thread after the webpage or the web browser is closed?

like image 333
ben Avatar asked Jan 12 '18 03:01

ben


1 Answers

HTTP Request cannot be cancelled. General guideline is, the REST calls should be very short. If in case, your REST calls are long running, recommendation is to break into granular calls.

If that is not an option and if you want to cancel a back-end processing, following option can be tried

  • For every back-end call, return a job id using which server can uniquely identify and return it to the client

  • Detect browser close

  • Expose a new Service to cancel based on the Unique Job Id
  • Handle logic in Server

This will require considerable amount of change!

like image 96
CGS Avatar answered Sep 19 '22 13:09

CGS