Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / December 2003

Tip: Looking for answers? Try searching our database.

How to kill a connection

Thread view: 
Bob Rivers - 09 Dec 2003 17:37 GMT
Hi,

I have a problem, and I don't know how to solve it.

We have a web application (done in java/jsp, running under tomcat
4.1.29/j2sdk 1.4.2) that establishes a connection with postgres 7.3.2.

We are using jdbc (7.3.1) to do it, but we are not using connection
pool (my client security police determine that all connections to the
database must be done per user basis).

So, when the user do the login, we create a connection to this user.
When the user closes the application, we close the connection. No
problem, everything works well.

But, if the user closes the window abnormally (for example, shutting
down the browser window without clicking my application logoff button)
the connection opened will be open forever.

This connection will be killed only if I shutdown tomcat and/or
postgres.

My question is: How do I kill an idle connection?

I don't want to do it manually. I was thinking about a thread that
verifies the connection. If this connection is idle more that x
minutes, I could kill it.

Another way, is to setup a timeout for the connection. If it is idle
for more that x minutes, postgres should kill it automatically.

Is it possible? How do I do that?

TIA,

Bob
Paul Thomas - 09 Dec 2003 20:08 GMT
> Hi,
>
[quoted text clipped - 28 lines]
>
> Is it possible? How do I do that?\\

PostgreSQL connections never time out so that way's a non-starter. You
might be able to detect when the session invalidates/times out using
HttpSessionBindingListener.

HTH

Signature

Paul Thomas
+------------------------------+---------------------------------------------+

| Thomas Micro Systems Limited | Software Solutions for the Smaller Business |
| Computer Consultants         | http://www.thomas-micro-systems-ltd.co.uk   |
+------------------------------+---------------------------------------------+
gnazio - 10 Dec 2003 00:54 GMT
> Hi,
>
[quoted text clipped - 32 lines]
>
> Bob

I worked on a project with tomcat ~4.18 and oracle (developed on
websphere but switched to tomcat because it was too expensive for our
customer).
There was a legacy client-server application accessing the same
database and so I should leave it unmodified.
The security for that application was designed using the rdmbs
authentication/authorization.
Moreover every operation was logged on a table by triggers and the
username was also logged.
I've found that with that version of tomcat, the method
getConnection(String username, String password) on the tomcat
datasource was not implemented and so the triggers wasn't able to know
who was making what.
Now I've heard that the method has been implemented and so every
connection from the pool should result 'opened' by the username passed
to the method.
Differently I solved my problem using tyrex (now at
http://tyrex.sourceforge.net/) and I think that it's an even better
option.
Your code could gain in efficiency and, why not, also in elegance.
I hope I can help you if you need help with it.

p.s.
please, feel free to correct my English...I'd like to improve myself
with it! :-)
Herman Timmermans - 10 Dec 2003 05:17 GMT
> Hi,
>
[quoted text clipped - 32 lines]
>
> Bob
You should implement the HttpSessionListener interface.  In case a session
is invalidated either by a pre-defined time-out or when the user closes his
browser, the sessionDestroyed method is called.  Use this method to
clean-up whatever that needs to be done in your database when the user
forgets to do a proper logoff.
Brgds,
Herman
Signature

Suse Linux Professional 8.1 on Athlon 1.1 Ghz 512 Mb
Anti Spam = remove the "dot" and the "at"
Registered Linux User #264690



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.