wood burning stoves 2.0*
The moose likes Servlets and the fly likes Handling too many ajax requests Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Handling too many ajax requests" Watch "Handling too many ajax requests" New topic
Author

Handling too many ajax requests

Dhaval J. Patel
Ranch Hand

Joined: Mar 10, 2011
Posts: 90

Hello everyone,

I am working on a booking system right now. On one of the pages I have a list of checkboxes that represents one item that you can book. So everytime you click on that checkbox an ajax request is sent to the server which would return the updated cost. My boss said that this is an absolute requirement to update the cost each time the user clicks on a checkbox.

I am thinking that everytime a user clicks, an ajax request would come in, wouldnt it degrade the performance of my webpage if a user keeps on clicking. Is there any way to address this issue? Some kind of mechanism that would hold the ajax request till the user stops clicking and then I could send the request.

I thought of putting a timer in javascript to some interval before a request is sent, but that wouldnt work as the user would have to wait for the timer to finish before he can click the next checkbox ( if only I could run multiple threads in javascript, but that would get too complicated)

Any Help would be appreciated,

Thanks in advance
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18121
    
    8

So to summarize: you don't know if there is a problem, but your only "solution" has the side effect of annoying the user. Which of course you don't want to do.

And really, how fast can your users click anyway? I suggest you are suffering from "Premature Optimization" (you could look it up). Don't solve problems until you know they exist.
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
What are the chances of turning the ajax call into a local javascript one?
If you check/uncheck this checkbox, the price goes up/down by $x.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18121
    
    8

Also, AJAX is asynchronous (that's what the first A stands for) so there shouldn't be any problem with two submitted requests overlapping. Unless you did something careless and made your servlet not be thread-safe, that is. And: is the response time for calculating the updated code annoyingly slow? If that's the case you might find the users clicking the same checkbox twice because they aren't seeing the result in a timely fashion. But basically, as I said, that shouldn't be a problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Handling too many ajax requests
 
Similar Threads
Ajax.InPlaceEditor and manual enterEditMode
how to show whick checkbox is checked in jsp page without submit?
how to prevent double clicks on hyper link.
Help with JavaScript Pop-Unders?
JSP/HTML/Javascript/XML task: Need Consultation