Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web applications and multi-threading

I'm working on porting a desktop application (WinForm) to a web application (Java/Spring/JPA). The problems are many and I'm struggling a bit...

Now the problem is threading!

In the original application, that performs the export of certain data from the DB, there is a progress-bar indicating the progress of the process.

I want to port this progress-bar in the new web application. To do this I thought of using AJAX and use a separate thread to run the data export.

The main concerns are:

  • Am I following the right approach? Are there problems using multi-threading in web applications?
  • If during the export process F5 or refresh button are pressed what exactly happens? How can I stop the process?
  • How do I update the progress bar periodically? Do I have to make calls via ajax to the server?
like image 484
davioooh Avatar asked Jul 07 '26 18:07

davioooh


1 Answers

I'm primarily an ASP.Net developer but from what I know of the HTTP protocol this just isn't the way to go about it. I've seen a lot of fairly clever solutions for this but in the end what becomes clear is that the HTTP protocol simply isn't designed to work like this.

Obviously you're aware that a flash or silverlight app would be able to do this but that comes with it's own set of issues.

Myself I prefer to keep all the weirdness on the server. In the past I've had to come up with a way to deliver several thousand emails through a web application and update the user on how it's coming along. I designed a set of tables to act as a queue. The web application would simply place any delivery requests in this queue and the progress bar would be determined by a request that checks the status of the items in the queue. Running in the background was a windows service which would also check this queue and was actually responsible for delivering the mail and setting the status of each item as it completed or failed.

It was a bit difficult to develop since windows services can be tricky but once it was up and running it was extremely smooth and reliable. Depending on your circumstances perhaps a simple scheduled task set to run every few minutes would do the trick for you.

like image 198
Spencer Ruport Avatar answered Jul 10 '26 09:07

Spencer Ruport



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!