[concurrency-interest] question about ExecutorCompletionService

Dhanji R. Prasanna dhanji at gmail.com
Thu Aug 31 08:43:07 EDT 2006


How about using generics to type ExecutorCompletionService?
Something like:

class ExecutorCompletionService<EX extends Executor, V> {
//...

EX getExecutor()..

}

then you could do:
ecs = new ExecutorCompletionService<ExecutorService, ..>(..);
ecs.getExecutor().isTerminated();

It's not much but you avoid the ugly cast.

On 8/31/06, Doug Lea <dl at cs.oswego.edu> wrote:
> yangjs wrote:
> > hi,all
> >   I have a Consumer poll task from ExecutorCompletionService ,this
> > class has  no method such as /isTerminated/, when app is shutdown, I
> > don't know when to shutdown my Consumer ,even if poll return null,.I
> > can't accept consumer lost task . if  ExecutorCompletionService have
> > method isTerminated as follow,thing will be simple. I can check when
> > service poll return null and service isTerminated, my consumer can
> > shutdown safely. is right??
> > why not provide such method ?
> >
> > public boolean isTerminated(){
> >    return executor.isTerminated();
> >  }
> >
> >
>
> This is a pretty good suggestion; thanks!
> Except that ExecutorCompletionService requires only an Executor,
> not an ExecutorService, and Executors don't necessarily
> have lifetime control methods (shutdown, isTerminated, etc).
> So in cases where people use some custom Executor that is
> not also an ExecutorService, the method can't be implemented.
>
> So the best we could do is add method
>    public Executor getExecutor() { return executor; }
> And you would then need to check termination using the ugly:
>    ((ExecutorService)(ecs.getExecutor()).isTerminated();
> (and being prepared for cast failure.)
>
> We could in fact compatibly add method getExecutor() because
> this is a concrete class and so doesn't impact other interfaces
> etc. And it would be handy in those cases where you
> don't otherwise have a reference to the executor used to create
> the ExecutorCompletionService. But unfortunately, nearly all
> uses of this would require casting of result, making it
> a bit ugly. Perhaps there is some better way of going about
> this with equivalent but nicer effect?
>
> -Doug
>
>
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
>


More information about the Concurrency-interest mailing list