|
Re: How to use Callable instead of Runnable with ScheduledThreadPoolExecuto: msg#00001java.jsr.166-concurrency
It's hard to see how to make this work. Would you expect to receive the list of Futures upon submission of the periodic task? In what order would you wait for the results? Instead, why not use a callback style? interface PeriodicTaskListener<T> { void resultReturned(T result); void exceptionThrown(Exception exception); } class PeriodicTask<T> implements Runnable { private final Callable<T> callable; private final PeriodicTaskListener<T> listener; PeriodicTask(Callable<T> callable, PeriodicTaskListener<T> listener) { this.callable = callable; this.listener = listener; } public void run() { try { listener.resultReturned(callable.call()); } catch (Exception e) { listener.exceptionThrown(e); } } } Then you can use it like this: scheduledThreadPool.scheduleAtFixedRate(new PeriodicTask<Long>( new Callable<Long>() { public Long call() throws Exception { ... compute some value ... } }, new PeriodicTaskListener<Long>() { public void resultReturned(Long result) { ... do something with result ... } public void exceptionThrown(Exception ex) { ... do something about ex ... } }, 5L, 5L, TimeUnit.SECONDS // every five seconds )); --tim On 10/2/06, Robert Bowen <syg6@xxxxxxxxx> wrote:
_______________________________________________ Concurrency-interest mailing list Concurrency-interest@xxxxxxxxxxxxxxxxxxxx http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | How to use Callable instead of Runnable with ScheduledThreadPoolExecutor?, Robert Bowen |
|---|---|
| Next by Date: | Re: PriorityBlockingQueue question, David Walend |
| Previous by Thread: | How to use Callable instead of Runnable with ScheduledThreadPoolExecutor?, Robert Bowen |
| Next by Thread: | Re: PriorityBlockingQueue question, David Walend |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |