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.
Hi, All. I've done some searching of the forums and couldn't find an adequate answer to my question. Basically, I'm trying to set the timeout for establishing connections to the database. I've attempted to use the following:
I have a method which contains the above code, and it's purpose is simply to check if a database is online. The problem is, if the database cannot be reached, the above DriverManager will not timeout for approximately 1 minute. It seems to ignore the call to setLoginTimeout().
I certainly appreciate any comments or suggestions. Thanks!
I'm not sure the 'appropriate solution' for what you are doing, but you could accomplish the same using threading. Spawn a new thread that outputs some value when its complete. Then from the original program, go to sleep for some amount of time (say 10 seconds) then wake up and check if the thread you were waiting for has outputted its value. If it has not, assume the database is offline and/or could not be reached.