deniskuzZ commented on code in PR #5174: URL: https://github.com/apache/hive/pull/5174#discussion_r1553574780
########## common/src/java/org/apache/hadoop/hive/common/ExecutorUtils.java: ########## @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hive.common; + +import java.util.Collection; +import java.util.List; +import java.util.concurrent.CancellationException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.collect.Lists; + +public class ExecutorUtils { + private static final Logger LOG = LoggerFactory.getLogger(ExecutorUtils.class); + + /** + * Waiting for futures to finish and return any exceptions caught. + * This implementation is borrowed from iceberg's Tasks. + * @param futures + * @return + */ + public static Collection<Throwable> waitFor(Collection<Future<?>> futures) { Review Comment: that could be replaced with CompletableFuture API ```` try { List<CompletableFuture<Void>> asyncTasks = new ArrayList<>(); for (Runnable task : tasks) { CompletableFuture<Void> asyncTask = CompletableFuture.runAsync( task, executor) .exceptionally(t -> { LOG.error("Error due to :", t); return null; }); asyncTasks.add(asyncTask); } //Use get instead of join, so we can receive InterruptedException and shutdown gracefully CompletableFuture.allOf(asyncTasks.toArray(new CompletableFuture[0])).get(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return; } catch (Throwable t) { LOG.error("Caught an exception while executing {}", t.getMessage()); throw t; } ```` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
