I am coding servlet part in my project. Now I am facing a problem on how to detect the http client that sends http query to my servlet is cancelled / killed by users.
I have a working scenario like this: a user sends http query to my servlet, my servlet parses query data and according to the contents of the http query, my servlet issues SQL calls via JDBC. When SQL queries finish, the servlet reformats the SQL results and send them back to http client. For some reason, either the SQL takes really long time or the DB server is slow, or whatever, during the execution period of SQL queries, my servlet just waits there and sends nothing back to http client. From the front user's standpoint (the front user issues http queries), he thinks that his http query is "dead", and he performs a kill or cancel operation to stop the http query.
Now my servlet needs to detect this kind of action, while it is still waiting for SQL queries to end, in order to cancel the SQL queries and to save DB resources.
How to do this?
Post by:Bear Bibeault
Originally posted by Howard Zhao: Ihe thinks that his http query is "dead", and he performs a kill or cancel operation to stop the http query.
How does the user perform this kill or cancel operation? Closes the browser? Navigates to another page? Unplugs the computer?
Post by:Howard Zhao
Thank you for your prompt reply. I am really appreciated.
The user can: 1 close the browser if he is using browser to send http query to the servlet. 2 perform a �Cancel� operation in a MFC based c++ client side program. The mentioned program constructs http query and sends it to the servlet. 3 close the mentioned program.
Post by:Bear Bibeault
Detecting browser close is difficult to do, so it's best to just let that one go. With regards to fat clients, you can do whatever you want using the facilities of the programming platform. But there's nothing built into the Servlet API to help you out with this. You'll need to come up with your own notification sub-system.
Post by:William Brogden
Author and all-around good cowpoke
You can't detect the browser closing, but you will get an IOException when your servlet tries to write to the response output stream and finds it has been closed by the client. Perhaps your servlet could write and flush a few bytes every N seconds - this would require that you run the database query in a separate Thread.
Bill [ December 20, 2007: Message edited by: William Brogden ]
Normally trees don't drive trucks. Does this tiny ad have a license?
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database