Exemplo n.º 1
0
 public void printPricesStream() {
   long start = System.nanoTime();
   CompletableFuture[] futures =
       findPriceStream("myPhone")
           .map(
               f ->
                   f.thenAccept(
                       s ->
                           System.out.println(
                               s
                                   + " (done in "
                                   + ((System.nanoTime() - start) / 1_000_000)
                                   + " msecs)")))
           .toArray(size -> new CompletableFuture[size]);
   CompletableFuture.allOf(futures).join();
 }
  public void stop() {

    if (stopped) {
      throw new RuntimeException("Already stopped or in progress");
    }

    stopped = true;

    CompletableFuture<?>[] futures =
        cachedDispatchQueues
            .values()
            .stream()
            .filter(v -> v != null)
            .toArray(CompletableFuture<?>[]::new);

    CompletableFuture.allOf(futures).join();

    service.shutdown();
  }