views:

12

answers:

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 machines ipaddress 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 useing Futures and callables etc.

This all went fine as well.

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

Future 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 queue = new LinkedBlockingQueue(20);

private static final ExecutorService executorService = new ThreadPoolExecutor(poolSize, maxPoolSize, keepAliveTime, TimeUnit.SECONDS, queue);
private static final CompletionService completionService = new ExecutorCompletionService(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 chnaging 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 happns?

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

why does (attempting) to run multiple inetAddress.isReachables fail?

I am being very dense? :-(

Can someone enlighten me please?

Cheers

Dick Dastardly (Drat and Double Drat!)