File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "Handling too many ajax requests" Watch "Handling too many ajax requests" New topic

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

Joined: Oct 14, 2005
Posts: 19973

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

Joined: Jul 06, 2005
Posts: 1580
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

Joined: Oct 14, 2005
Posts: 19973

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:
subject: Handling too many ajax requests
It's not a secret anymore!