Subject | Re: Connection.close() and hard reference issue |
---|---|
Author | Roman Rokytskyy <rrokytskyy@yahoo.co.uk> |
Post date | 2003-01-29T08:00:38Z |
> If I have hard references to this instance, for exampleHard references are not related to returning connection to the pool,
> Statement st = conn.createStatement();
> and then I call conn.close().. will this free the connection
> and return it to the pool, or the connection will stay used untill
> timeout?
but only to the garbage collector work. conn.close() will return
pooled connection to the pool. Not closed pooled connection will
never be returned to the pool. If garbage collector decides to
collect it, it will call finalize() method that in turn will close
_physical_ connection. I do not know if pool will notice this. In
general, any not closed connection should be considered as resource
leak.
Typical block of obtaining connections is:
Connection connection = dataSource.getConnection();
try {
...
} finally {
connection.close();
}
Note, connection is declared inside method body. If you want it to be
an instance member (object attribute), you have to set it explicitly
to null in finally block.
Timeout is used to close _physical_ connections in the pool that were
not used for a long time. This option does not affect pooled
connections.
Best regards,
Roman Rokytskyy