[concurrency-interest] How to subclass CompletableFuture?

cowwoc cowwoc at bbs.darktech.org
Mon Oct 27 04:13:08 EDT 2014


Hi Kasper,

I actually tried composition before subclassing, but I found that
thenComposeAsync() would hang indefinitely. I never did figure out the cause
but I suspect it has to do with the fact the code invokes:

  dst = new CompletableFuture<U>();

in a couple of places. In other words, I don't think composition is possible
either.

Has anyone successfully extended this class using subclassing or
composition? If not, is it possible for us to add methods which would make
it suitable for extension?

This class violates DRY if users wish to execute multiple tasks
asynchronously on the same (custom) Executor. I appreciate the fact that
some people might want to specify a different Executor per task, but the
inability to add a Facade on top of this class is making it very painful to
use.

Gili


Kasper Nielsen-4 wrote
> I've found CompletableFuture impossible to extend. Mainly because all the
> methods returns new instances of CompletableFuture. Where you probably
> want
> to return new instances of your CompletableFutureSubClass.
> 
> So I think the proper way is using composition. However with all the
> methods in CompletableStage it takes some determination.
> 
> - Kasper
> 
> 
> On Mon, Oct 27, 2014 at 3:21 AM, cowwoc <

> cowwoc at .darktech

> > wrote:
> 
>> Hi,
>>
>> I believe that CompletableFuture was designed to allow for subclassing
>> but
>> I
>> can't seem to figure out how to implement such a subclass:
>> http://stackoverflow.com/q/26579139/14731
>>
>> I figured if anyone would know how to implement this kind of thing, it
>> would
>> be you :)
>>
>> Thanks,
>> Gili
>>
>>
>>
>> --
>> View this message in context:
>> http://jsr166-concurrency.10961.n7.nabble.com/How-to-subclass-CompletableFuture-tp11382.html
>> Sent from the JSR166 Concurrency mailing list archive at Nabble.com.
>> _______________________________________________
>> Concurrency-interest mailing list
>> 

> Concurrency-interest at .oswego

>> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>>
> 
> _______________________________________________
> Concurrency-interest mailing list

> Concurrency-interest at .oswego

> http://cs.oswego.edu/mailman/listinfo/concurrency-interest





--
View this message in context: http://jsr166-concurrency.10961.n7.nabble.com/How-to-subclass-CompletableFuture-tp11382p11384.html
Sent from the JSR166 Concurrency mailing list archive at Nabble.com.


More information about the Concurrency-interest mailing list