• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cancel JDBC Connection when Browser Cancel

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please I have a pool of connection to an Oracle DataBase, and several JSP sharing that pool of connection. All the servlet in my server ask for a new Connection from that pool every time a user does a query. But I want to close the connection everytime the user press stop in the browser or when some timeout has expired. Can anyone give me some ideas how to detect that?

I am using a class which manages the pool of connection, store that class like a ServletContext attribute, and every time any java servlet needs a new connection that class manage the opening of the new connection, and give the new connection to the servlet. So in the case somebody cancel the search, how can I detect that in the servlet (or in the pool connections class) and cancel the connection.

Please any note, paper or advice will be very helpful
Thanks.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kened,
Welcome to JavaRanch!

There isn't any way of the server knowing that the browser cancelled the request. Two best practices:
1) Use the application server's connection pool (It sounds like you may already be doing this.)
2) Close the connection after each query. Don't rely on the user telling you when the request is done. You know when the query is complete, so give the connection back to the pool then.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like want to dedicate a connection to a session, dont dedicate a connection to a session. you would shortly slip into performance lack.

Have you considered this.

no of sessions = no of connections.


Your server would definitely turn into a bottleneck condition. Why a new connection always. You are using connection pooling mate. You forced me to think you as, you dont really know the pooling mechanism. is it?
[ February 04, 2005: Message edited by: Adeel Ansari ]
 
Kened Fernandez
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys, Thanks for the responses. Sorry for the delay.
I am using my own connection pool class, already made in the company where I work, but I have noticed when a user cancel the query, the connection (and the query) is still alive, and I would like to avoid this.

I am closing the connection everytime the query finished, but what happen if the result of the query is big, and the user cancel it, the connection continues...What can I do to avoid this?

Thanks.
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kened,
Now I understand! No, there isn't any way of the server knowing that the user cancelled the request on the browser. You have to let the request complete or timeout and naturally close the connection then.
 
reply
    Bookmark Topic Watch Topic
  • New Topic