I have a custom connection pool, which polls the database server every 2 seconds to query whether the SQL database is still alive. This is done so that if it is determined that the SQL server is dead, the connections are cleared and re-created, thus make sure all connection are fine. However, my friend, a network engineer told me that any TCP based connection will not die instantly, even if there is a temporary phyiscal disconnection i.e. if the problem arranges itself within some 50 seconds, the TCP based connections will still be ok. These disconnections may occur frequently due to small changes in firewall maintenance and otherwise, my question is, will the connections be ok, if the connection is restored within a few seconds, and therefore should I increase my polling interval to the "stay-alive" period of the TCP connections? Thanks
There's no place like 127.0.0.1
Peter den Haan
posted 13 years ago
Don't worry, this is all handled at the TCP/IP protocol level. If there is a temporary network glitch, I/O will block while the TCP/IP stack tries to recover. If the network remains down, the Socket will eventually time out and throw an IOException which the JDBC driver will turn into an SQLException. If, on the other hand, the problem goes away, then the only consequence is that your once-every-2-seconds check may take a little while to execute. - Peter
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads