This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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