How to check url is valid or not for thousands of nodes together in very short time?
<p>I have a need of checking a particular url <code>"http://16.100.106.4/xmldata?item=all"</code> if it is working or not? Now thing is that, I use the below code if url does not work then connection timeout waits for about 20 seconds before giving exception. Now, I have to check the URL for around 20000 IPs and i can not afford to wait for that long time. Threading can be an option but with that also I am not sure till how much thread should I go. I want the whole operation to be done in matter of seconds.</p>

<pre><code>public static boolean exists(String URLName){
     boolean available = false;

          try{
                final  URLConnection connection = (URLConnection) new URL(URLName).openConnection();
                connection.connect();

                System.out.println("Service " + URLName + " available, yeah!");
                available = true;
            } catch(final MalformedURLException e){
                throw new IllegalStateException("Bad URL: " + available, e);
            } catch(final Exception e){
                // System.out.print("Service " + available + " unavailable, oh no!", e);
                available = false;
            }
            return available;
  } 
</code></pre>
