Using Java with async code calls

private void runAndWait(){
   final List<CompletableFuture<Void>> futures = new ArraysList<>();
       for(int i=1; i<11; i++){
           futures.add(CompletableFuture.runAsync(()->magic(i)));
       }
   CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
}


private void magic(int i){
    try{
        TimeUnit.SECONDS.sleep(i*10);
        System.out.println(i +" is done");
    }catch(Exception e){}
}

Execute async call to a magic function and then wait for them to finish