Question: I'd like to subclass [CompletableFuture](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html) to override the default `Executor`. That is, if a user invokes a method without specifying an `Executor`, I want my own `Executor` to get used instead of the one normally used by `CompletableFuture`.

The Javadoc hints at the possibility of subclassing:

> 
> All CompletionStage methods are implemented independently of other public methods, so the behavior of one method is not impacted by overrides of others in subclasses.
> 
> 
> 

How am I supposed to implement static methods like `CompletableFuture.supplyAsync()` in the subclass if the underlying implementation depends on methods like `internalComplete()` which is package-private?

**How is one supposed to subclass CompletableFuture?**

---

What I'm trying to do...
------------------------

My user code needs to execute multiple tasks asynchronously using the same executor. For example: `CompletableFuture.supplyAsync(..., executor).thenApplyAsync(..., executor).thenApplyAsync(..., executor)`. I'd like the custom `CompletableFuture` implementation to use the first executor throughout all follow-up calls.

Answer: 
Answering the original question -- **How is one supposed to subclass CompletableFuture?**

Probably starting from a clean-room CompletionStage interface implementation (rather than from the concrete CompletableFuture class) a is a better option. Please take a look here:

<https://github.com/lukas-krecan/completion-stage>
Async programming is widely misunderstood. Theoretical approach is to represent async program as Petri net, where main components are tokens, places, and transitions. From programming point of view, transition should be split further into firing rule and action. Logical chain appears to be too long, programmers prefer oversimplified scheme "event-reaction", which does not work in any complex cases. CompletableFuture is even more restricted, with scheme "action - primitive transition - action".

In your case, each stage has to be feed from two sources: result of previous stage and resource token allowing to access the web service. CompletableFuture simply does not fit for such cases. I would recommend first draw the Petri net for your case, and then implement basic infrastructure from scratch, using classes with synchronized methods. Or try my async library [df4j2](https://github.com/rfqu/df4j2), which allows to build transitions with several places.