mardi 26 mai 2015

Run multi threads in servlets

I have couple of processes (calling to a 3rd party service and get response, query database and get results, do some IO operations etc) to be executed in my servlets. Moreover, those processes are time consuming and if the 3rd party call which is the first process, response fails, the rest of processes should be terminated too.

I am to run all these processes as multi threads using Executors. As soon as possible, the response of first process is available, the servlet should send response ( redirect to a page ) . When the rest of all process are finished, the output should be sent to the page again (something like push to the browser).

My first attempt was to send ajax requests from the browser and handle all these processes. But it is less secure. So, let me know an approach to run these threads and once first process is done, send the response and later return the rest of outputs.

Aucun commentaire:

Enregistrer un commentaire