Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Set Timeout for Connections

 
Jeffrey Hunter
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

:jeff
 
Scott Selikoff
author
Saloon Keeper
Posts: 4020
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic