title: Java CompletableFuture.anyOf(manyfutures).thenRun( runnable ) only runs once
body: <p>I was doing </p>
  
  <pre><code>CompletableFuture.anyOf(manyfutures).thenRun( new Runnable() { } }
  </code></pre>
  
  <p>but the code in the runnable is only running once! I was expecting it to run many times, every time any of the futures completes. </p>
  
  <p>How can I run a block of code everytime any of the futures completes? In optimal fashion, meaning this won't do: </p>
  
  <pre><code>    public static void append(final CompletableFuture[] futures, Runnable runnable) {
              for (CompletableFuture future : futures) {
                      future.thenRun(runnable);
              }
      }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>I am using a ThreadPoolExecutor which I want to append more work to when an X number of runnables have executed.</p>
  
  <p>Is there a way to listen for this and supply more work when that happens? </p>
  
  <p>The alternative is that I stack thousands of work in the beginning, but that is not optimal either.</p>
  
  <p>I am doing </p>
  
  <pre><code>... queue = new LinkedBlockingQueue&lt;Runnable&gt;(); 
  new ThreadPoolExecutor(nThreads, nThreads, 0L, TimeUnit.MILLISECONDS, queue);
  </code></pre>