[concurrency-interest] Simple ScheduledFuture problem

Tim Peierls tim at peierls.net
Thu Aug 17 14:55:22 EDT 2006


On 8/17/06, robert lazarski <robertlazarski at gmail.com> wrote:
>
> Thanks Dave and Joe. I implemented the changes you two mentioned (I
> hope) and now invoke a FutureTask inside the Runnable of the
> ScheduledFuture .


Maybe instead of creating a new thread for each PingFuture, you could
decouple the execution policy of PingFuture from the scheduling of PingTask
using an ExecutorService. Specifically, instead of the following code in
PingTask.run:

FutureTask<?> f = new FutureTask<Object>(new PingFuture(), null);
> Thread thread = new Thread(f);
> thread.start();
> // 5 seconds to finish connect or will timeout
> f.get(5000, TimeUnit.MILLISECONDS);
>

You could write:

    exec.submit(new PingFuture()).get(5000, TimeUnit.MILLISECONDS);

where exec is initialized with Executors.newCachedThreadPool().

--tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20060817/8b080dee/attachment.html 


More information about the Concurrency-interest mailing list