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) {
;
}
}
}
}