[concurrency-interest] Simple ScheduledFuture problem
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
FutureTask<?> f = new FutureTask<Object>(new PingFuture(), null);
> Thread thread = new Thread(f);
> // 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().
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Concurrency-interest