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: 
Your goal is to limit the rate of access to the web service. Your solution is to use special executor which introduces delays. This is not the best solution, because some function in the chain can spend some time for other activity, or just wait too long in the queue to processor on O/S level and thus need not be delayed before accessing the web service, but will be delayed by the executor anyway. Delays should be embedded in the module which actually performs requests to the web service. It should remember the time of the previous request and, if it is too small, just call Thread.sleep() before sending request via socket. This way you need not any CompletableFuture and can call functions directly like f3(f1(f0))). At least it is more readable.
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.