This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Joe Ess

HttpURLConnection locks up on connect()  RSS feed

Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public static boolean isReachableURL(URL url)
throws MalformedURLException, IOException, Exception {
System.out.println("Testing to see if URL connects");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
System.out.println("Created HttpURLConnection object");
boolean isConnected = (conn.getContentLength() > 0);
return isConnected;

I am trying to simply determine if a URL provided is a "reachable URL", if so, return true, else, return false.

On most URLs I have no problem distinguishing reachable from unreachable, but if you try something like this:

It will lock up tight as a drum and I have to break into Windows Task Manager to stop the process as it runs as an infinite loop at this point.

So how can I reliably determine if a URL is reachable or unreachable?

Author and ninkuma
Posts: 66789
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use UBB code tags (read this) when posting code to preserve the formatting.

Also, as this really has nothing to do with JSP per se, it's been moved to the Internet Protocols forum as a more appropriate location.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!