We see situations when our database connection org.apache.commons.dbcp.BasicDataSourcedies with socket write errors:
com.microsoft.sqlserver.jdbc.SQLServerException: Connection reset by peer: socket write error
All subsequent attempts to write to the connection do not work, of course:
com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed.
After updating the code, in order to catch such exceptions and request a new connection when it occurs, it again failed. Do I correctly suspect that the call DataSource#getConnection()does not actually give a new connection each time it is called? Isn't that just reusing an existing connection that is closed?
If I'm right, what is the right way to throw away the old connection and request a new one?
EDIT: here is a more succinct version of what I would like to know:
Connection c1, c2;
c1 = DatabaseManager.getConnection();
// c1.close() not called
c2 = DatabaseManager.getConnection();
"c1 == c2" ? ? , , , " ":
Connection c1;
c1 = DatabaseManager.getConnection();
// c1.close() not called
c1 = DatabaseManager.getConnection();