Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to detect http client is cancelled / killed?

 
Howard Zhao
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Howard

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Howard Zhao
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Howard
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic