0

I have a jsp/servlet based web app.

I have a button "Clean Up" which calls a servlet and the request goes till DAO class.DAO class performs different DB activities like, moving data from Master table to backup table, then deleting data from master table etc.

As of now this activity is Synchronous and user needs to wait until a response is sent.

I want to implement the same scenario as an Asynch task with user just getting a message as " Clean Up Activities Triggered"

What could be the best/easiest way to perform this task. I cannot use scheduler.

My Container is TomCat.

3 Answers 3

2

Simplest but a different solution for this could be to use some AJAX behavior in the client side. There are lot of simple/powerful frameworks(JS files) to help you achieve AJAX in your page. Using AJAX, you just submit the request asynchronously and display the client side message "Clean Up Activities Triggered", while request is being processed in the server side. If user wait, server process will return and display a "success" message otherwise user is free to navigate other pages or perform other actions.

Sign up to request clarification or add additional context in comments.

Comments

2

ExecutorService is the most robust solution. Creating a simple thread is enough as well. However the bigger problem is synchronization. Use Semaphore to control whether two users aren't cleaning up simultaneously.

Comments

0

we did this for our project once and it worked pretty well.

We sent the 200 ok to the user as long as there no issues processing the request. And we used the java executorservice to do the cleanup.

And in case something went wrong notified the user separately.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.