4

I have a connection pool. In the getConnection() method I poll a connection from the queue to a variable and check whether it is closed by isClosed() method. If it is closed I set to the variable new connection by DriverManager.getConnection(url, user, password) method.

The question is: do I need to close the connection mannualy by close() method before rewriting the varible to ensure that the connection will be collected by the Garbage Collector?

aspirisen
  • 965
  • 13
  • 29
  • 1
    connection is already close, so what are you going to get out of calling close again.. nothing? – SMA Dec 06 '14 at 11:03
  • Maybee the close method doing something else. I was told that the Garbage Collectore do not collect conections if they are not closed. – aspirisen Dec 06 '14 at 11:17
  • You were told wrong. But `isClosed()` doesn't mean the connection was closed by the database. It means *you* closed it. – user207421 Dec 07 '14 at 16:05

1 Answers1

2

It is not needed (Recommended).

If you call close() manually after the connection has been closed, there will be no action performed on that connection object.

ashokramcse
  • 2,841
  • 2
  • 19
  • 41