I have several processes (accessing a third-party service and receiving a response, querying the database and getting the results, performing some I / O, etc.) that will be executed in my servlets. Moreover, these processes require a lot of time, and if the third-party call is the first process, the response fails, the remaining processes must also be terminated.
I have to start all these processes as multiple threads using Executors. As soon as possible, the response of the first process is available, the servlet should send a response (redirect to the page). When the rest of the whole process is completed, the output should be sent to the page again (something like clicking on the browser) or redirected to another page (but then you need to have access to the rest of the thread that is already running.
My first attempt was to send ajax requests from a browser and process all these processes. But it is less secure. So let me know the approach for starting these threads, and as soon as the first process is completed, send a response and return the rest of the results later.
source
share