Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6377609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:53:46+00:00 2026-05-25T01:53:46+00:00

I have an application written in java that needs to find all the reachable

  • 0

I have an application written in java that needs to find all the reachable hosts on the network.

I use InetAddress.isReachable() to do this with a timeout of 2000 milliseconds.

I look up the current local machine’s IP address and based on that I attempt to reach the other IP addresses that end 1 – 255 missing out the local machines IP address.

It all works fine single threaded, just takes a long time as most of the IP addresses are not reachable as they do not exist so use up the 2 second timeout.

To speed things up (and try out concurrency in action :: Brian Goetz) i tried using Future and Callable etc.

This all went fine as well.

However i fancied using ExecutorCompletionService to give my users a more responsive application, so they could see results as they came available using

Future<Reach> reachedFuture = completionService.take();

Running this on a singleprocessor machine with the following config causes only 1 of the four reachable hosts to be identified:

private static final int poolSize = 10;
private static final int maxPoolSize = 10;
private static final long keepAliveTime = 120;

private static final LinkedBlockingQueue<Runnable> queue
        = new LinkedBlockingQueue<Runnable>(20);

private static final ExecutorService executorService
        = new ThreadPoolExecutor(poolSize, maxPoolSize, keepAliveTime, TimeUnit.SECONDS, queue);

private static final CompletionService<Reach> completionService
        = new ExecutorCompletionService<Reach>(executorService);

Changing it to this on a quad core machine also made it fail to detect all the reachable hosts:

private static final int poolSize
        = Math.max(2,Runtime.getRuntime().availableProcessors());

private static final int maxPoolSize
        = Math.max(2,Runtime.getRuntime().availableProcessors());

By changing the InetAddress.isReachable() timeout to 10 seconds made the last config work ok.

Also by changing the config as follows on the quad core machine also made it work with a 2 second timeout:

private static final int poolSize = 2;
private static final int maxPoolSize = 2;

Am I missing something very obvious why this happens?

What stops InetAddress.isReachable(2000) from detecting all the reachable hosts on my network?

Why does attempting to run multiple InetAddress.isReachable() calls fail?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:53:46+00:00Added an answer on May 25, 2026 at 1:53 am

    So I wrote a little test script on my Mac and I can’t get it to fail — regardless of the size of the pool. I did change the LinkedBlockingQueue to be unlimited otherwise I couldn’t submit all of the jobs. Also, after a while the isReachable() method was throwing a ConnectException so I had to handle that specifically. Is this the problem with your code @user423199?

    Here’s the code:

    http://pastie.org/2460991

    I’m wondering what OS you are running this on? Certain IP stacks may not like multiple threads doing ICMP packets within the same process. I would have thought that all modern operating systems would be smart about that but this may be a potential issue. It also may be some bug between the Java JRE and the OS stack.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a new application written in java that needs to read encrypted values
I am trying to write an application that uses java.net.Socket. I have also written
I have this application written in java to calculate pageranks. And the application takes
I have written an application in jsoup that needs to connect through company proxy.
I have application written in Java that is using EJB3 + Toplink. I'm using
Part of our java application needs to run javascript that is written by non-developers.
I have an application written in Java that uses a jar file(it uses more
We have a desktop application written in Java Swing that currently uses Java Web
We have a Java EE application running on Glassfish 3.1 that needs to accept
I have two applications written in Java that communicate with each other using XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.