473,326 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

The better approach????

sumittyagi
202 Expert 100+
I am asking a question in which servlet and jsp are included, but this question is about approach not about technical details of jsp, and servlets. it is about better approach for implementing AJAX in a particular scenario.

The scenario is:
step1:- I submit my request to a servlet from my jsp (normal request - non-ajax).

step2:- servlet takes my request, and creates a new thread (as the task is heavy and may consume time) which processes my task, and servlet returns back to the jsp.

NOTE:- thread will update a flag in database when task is complete.

step3:- on the jsp's onload event, a flag is checked, and if its false(false first time), then an ajax-request (asynchronous request) is sent to the servlet.

step4:- servlet will check for the flag in database(which is to be updated by the database and returns back to the jsp.

step5:- now the jsp checks the flag, if true then takes appropriate action else after 10 seconds jsp sends the same request (as in step3).

now my confusion is in step4 and step5.

request is again and again being sent to the server, so is it ok,

or the other side is ok, i.e:-
when ajax request is sent to the servlet, and servlet accepts the request (i.e. in step4), then if flag is false in database, then servlet sleeps for 10 seconds and after waking up again checks flag in database. and when flag becomes true, returns result.

Thanks in advance for any suggestion.
Mar 16 '07 #1
2 971
acoder
16,027 Expert Mod 8TB
I think the first approach is better because you are sending the request and getting an immediate response when you need to, though does it have to be only 10 seconds? The second approach just doesn't return a result until it is true.

That's my opinion, others may differ.
Mar 16 '07 #2
sumittyagi
202 Expert 100+
I think the first approach is better because you are sending the request and getting an immediate response when you need to, though does it have to be only 10 seconds? The second approach just doesn't return a result until it is true.

That's my opinion, others may differ.
Thanks acoder for your reply!

>>does it have to be only 10 seconds?
No it doesn't have to be 10 seconds, it is abstractly chosen time limit.

>>The second approach just doesn't return a result until it is true.
Yea! that's true, and this is where my confusion starts.
* in first case browser have to make a request again & again, which would consume client resources as well as network resources.

* in second case it will not return and will consume one request processing thread for a specified time(till request completes. But client is free to take any action till that time, as request sent is asynchronous in nature.

* I think both the alternatives are fine, but it is up to an individual, in what context s/he considers it.

Any other suggestions are welcome.
Mar 19 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

36
by: Ben Justice | last post by:
For a program in c, I need some random numbers for a system were people are placing bets. This is not a commerical project btw. Generally, I tend to rely on things from the standard library,...
3
by: mrhicks | last post by:
Hello all, I have a question regarding efficeny and how to find the best approach when trying to find flag with in a structure of bit fields. I have several structures which look similar to ...
16
by: Robert Zurer | last post by:
Can anyone suggest the best book or part of a book on this subject. I'm looking for an in-depth treatment with examples in C# TIA Robert Zurer robert@zurer.com
3
by: =?Utf-8?B?Um9sYW5kcGlzaA==?= | last post by:
Hi, I'm doing an application using C# and I have this question: I have a method called sqlQueryBD which receives a string sql query and executes it against a database. I also have a class called...
20
by: mike3 | last post by:
Hi. (Xposted to both comp.lang.c++ and comp.programming since I've got questions related to both C++ language and general programming) I've got the following C++ code. The first routine runs in...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.