When is a connection idle?
How do you know that exactly?
Not closing a connection is just a bug, that needs fixing.
The only solution would be (but can't be done i believe) if weak or soft or phantom
references (one of them) worked this way:
You keep one phantom/weak reference to your connection when you give it to the get
connection request.
then i want a event or a check a queu that says to me: Youre reference is the only
reference left.
That would be a great feature. But i don't think one of the weak references work this
way
johan
----- Original Message -----
From: "Nick Afshartous" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, February 26, 2001 8:42 PM
Subject: reclaiming Connections/GenericDatasource enhancement
>
> Has someone already implemented a solution to reclaiming
> open Connections that an app forgot to close ?
>
> If not can someone provide feedback to my proposal below, thanks.
> --
>
> Nick
>
>
> > From: Nick Afshartous <[EMAIL PROTECTED]>
> > To: [EMAIL PROTECTED]
> > Subject: DataSource enhancement: reclaiming closed connections
> > Date: Fri, 2 Feb 2001 13:45:48 -0500 (EST)
> >
> > I've started to sketch out an enhancement to the GenericDataSource
> > that will reclaim connections that an app forgot to close.
> > My current design is to add an inner class (below) to the
> > GenericDataSource class. Essentially the GenericDataSource
> > will have a daemon thread that periodically checks for idle
> > connections.
> >
> > Naturally, since this is my first attempt at Struts development I
> > have some questions and thoughts:
> >
> > - it occurs to me that simply returning idle connections to the
> > pool may not be safe. What if the original thread that requested
> > the connection starts to use it again while some other thread
> > is currently using the connection. Maybe the idle connection
> > should be destroyed and a new one created ?
> >
> > - configurable options: connectionTimeout
> >
>
>
> private class ConnectionCollector implements Runnable {
>
> public void run () {
>
> while (true) {
>
> // look for Connections that are not being used
> Date currentTime = new Date();
>
> for (int i = 0; i < usedConnections.size(); i++) {
> GenericConnection conn = (GenericConnection)
> usedConnections.elementAt(i);
>
> if ((currentTime.getTime() - conn.getLastAccessTime())
> >= connectionTimeout) {
> try {
> conn.close();
> } catch (SQLException e) {
> ;
> }
> }
> }
>
> // check every two minutes
> try {
> Thread.sleep(120000);
> } catch (InterruptedException e) {
> ;
> }
> }
> }
> }
>
>