Bug #11654 | isClosed does not report if underlying socket has been closed | ||
---|---|---|---|
Submitted: | 30 Jun 2005 8:10 | Modified: | 30 Jun 2005 14:19 |
Reporter: | Al Sutton | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | Connector / J | Severity: | S4 (Feature request) |
Version: | 3.1.10 | OS: | Java |
Assigned to: | CPU Architecture: | Any |
[30 Jun 2005 8:10]
Al Sutton
[30 Jun 2005 14:19]
Mark Matthews
Sorry. IsClosed() is not required to return true if the socket is closed. In fact, it is a violation of the JDBC specification to do so. IsClosed() _only_ returns true if something has called .close() on the connection. However, you should notice that if the driver has communicated with the server and _that_ communication has failed, the driver calls .close() on the connection internally and .isClosed() will return true. We don't check the socket before every communciation with the server because 1) there isn't a way to do it without sending data to the server and 2) If the socket is dead the driver will get an exception when it tries to send the data and it then cleans up the internal state of the connection and calls .close() on it. From http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Connection.html#isClosed(): "Retrieves whether this Connection object has been closed. A connection is closed if the method close has been called on it or if certain fatal errors have occurred. This method is guaranteed to return true only when it is called after the method Connection.close has been called. This method generally cannot be called to determine whether a connection to a database is valid or invalid. A typical client can determine that a connection is invalid by catching any exceptions that might be thrown when an operation is attempted. "