How can we determine the status of a Job a servlet is doing.
If a sservlet creates a Job Object and call its do() method which takes 2 minutes to complete and we want to show the users how much task it has completed so far on the front-end.
You'll have to
put the job in a session attribute, for example, or in some other shared map where you can find it in a subsequent request
start a new thread which invokes the job's long-running method
make sure every access to the job's status is properly synchronized
poll the server from your HTML page (by refreshing the page or submitting AJAX requests
Each polling request will just get the job from the session (or the shared map) and get its status.
Related
In ASP.NET when you have 2 AJAX requests on the same web page calling 2 controller actions, if they use the session then one will lock out the other
You can get readonly access to the session which can help, but not if you want to write to the session
You can override the session class, e.g.
https://www.red-gate.com/simple-talk/dotnet/asp-net/single-asp-net-client-makes-concurrent-requests-writeable-session-variables/, but this doesn't really help for the same reason
In my case the controller action calls a long running external server call. While this is happening ideally the session would be released and saved back to memory, and then when the call is finished the session would be read back in, possibly being blocked if another call is still proceeding
NB Whether or not the external server call is called in an async manner makes no difference unfortunately
Is there any way of doing this? Possibly by overriding some internal classes?
The webapp which I’m working on does some data manipulation at the back-end after a user clicks button. This process takes a long time to complete causing the browser to timeout. Therefore I’ve introduced an asynchronous ADO command which causes the page response immediately while the back-end process keeps running. That page also includes an AJAX call to check the status of the back-end process and when it detects that it is completed another AJAX request gets the result of that process form the back-end. All works as expected.
My question is regarding the ADO connection for this scenario as with the asynchronous execution the connection must not be closed.
Is there a way that I can reference the same connection object from another page (the result page requested by AJAX call) and close it ? Or should I just leave it for the server to kill it off eventually.
I was researching a bit for this answer with no success.
Is there a way that I can reference the same connection object from
another page
How about saving async connection in Session("xxx") variable?
I have a web application that performs just one heavy process.Now suppose any user has send a request, and servlet is processing (This processing may take about an hour). if the same user hits the link again knowingly or unknowingly before the previous request is completed. The app should not allow it and should display a message saying, we are already processing your previous request.
for example- User hits the link - www.example.com/myApp/saw.dll and servlet is processing. now before the processing finished, same user hits the same link again. I do not want the request to be processed again and just display a message that we are processing.
How to restrict the servlet from processing any new request from the same user if it is already processing previous request (from the same user)?
Hope my question is clear. Appreciate your valuable suggestion.
If I call a WebService Async using ASP.NET will the callback code still run even if the user is no longer physically on the page, or when the user leaves the page will the process terminate ?
Yes, if the user close the connection with the server, and your processing takes too much time, you get a throw of "connection close" and your process will terminate.
If you do not like that and you wish to keep the processing make a new thread that is not depend from the connection with the user, and synchronize it with the user return. If the user close the connection then the thread will finish normally, just you not show the results.
I'm new to web development so I'm not sure what's the best option for the problem that I'm having.
Basically I have a web application that calls a web service for processing some data.
This process may take a long time (hours) and I would to know if there is an easy way to send some status information to the client from time to time.
Right now, the client makes the request from the browser and it just waits there until it finishes.
How can I send some information from the web service? I would like to send a percentage and some additional text specifying what is being done.
Thanks
WCF services can be marked as [OneWay] so that they don't return a response.
or, you could have the service kick off the process in an async manner and then just return to the client that the process has/or hasn't kicked off.
Then, the client can poll another method as the other user has suggested.
If you process takes hours you definitely can't use a sync service because you'll hit your execution timeout or rather the connection timeout for the client.
Maybe you can poll another method for status?
If I were you, I would make the original request asynchronous, as in instead of waiting for the response, it just "starts" the task and returns immediately. Then I would have a separate method on your web service that the app can poll periodically to get the status of the job. once it completes, it can display the data like the original request was doing.
if you want to do it synchronously, you can turn off Response.Buffer and write directly to the response.