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.
Kened Fernandez<br />SCJP 1.4 (85%)<br />SCWCD in progress...
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.
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 ]
Joined: Feb 02, 2005
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?
author & internet detective
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.
subject: Cancel JDBC Connection when Browser Cancel