You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by xy...@apache.org on 2018/04/10 19:39:10 UTC
[32/50] [abbrv] hadoop git commit: HADOOP-15366. Add a helper
shutdown routine in HadoopExecutor to ensure clean shutdown. Contributed by
Shashikant Banerjee.
HADOOP-15366. Add a helper shutdown routine in HadoopExecutor to ensure clean shutdown. Contributed by Shashikant Banerjee.
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/0b345b76
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/0b345b76
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/0b345b76
Branch: refs/heads/HDFS-7240
Commit: 0b345b765370515d7222154ad5cae9b86f137a76
Parents: eb47c3d
Author: Mukul Kumar Singh <ms...@apache.org>
Authored: Sat Apr 7 16:29:01 2018 +0530
Committer: Mukul Kumar Singh <ms...@apache.org>
Committed: Sat Apr 7 16:29:01 2018 +0530
----------------------------------------------------------------------
.../hadoop/util/concurrent/HadoopExecutors.java | 34 +++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hadoop/blob/0b345b76/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/concurrent/HadoopExecutors.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/concurrent/HadoopExecutors.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/concurrent/HadoopExecutors.java
index 1bc6976..7a04c30 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/concurrent/HadoopExecutors.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/concurrent/HadoopExecutors.java
@@ -27,7 +27,7 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
-
+import org.slf4j.Logger;
/** Factory methods for ExecutorService, ScheduledExecutorService instances.
* These executor service instances provide additional functionality (e.g
@@ -91,6 +91,38 @@ public final class HadoopExecutors {
return Executors.newSingleThreadScheduledExecutor(threadFactory);
}
+ /**
+ * Helper routine to shutdown a executorService.
+ *
+ * @param executorService - executorService
+ * @param logger - Logger
+ * @param timeout - Timeout
+ * @param unit - TimeUnits, generally seconds.
+ */
+ public static void shutdown(ExecutorService executorService, Logger logger,
+ long timeout, TimeUnit unit) {
+ try {
+ if (executorService != null) {
+ executorService.shutdown();
+ try {
+ if (!executorService.awaitTermination(timeout, unit)) {
+ executorService.shutdownNow();
+ }
+
+ if (!executorService.awaitTermination(timeout, unit)) {
+ logger.error("Unable to shutdown properly.");
+ }
+ } catch (InterruptedException e) {
+ logger.error("Error attempting to shutdown.", e);
+ executorService.shutdownNow();
+ }
+ }
+ } catch (Exception e) {
+ logger.error("Error during shutdown: ", e);
+ throw e;
+ }
+ }
+
//disable instantiation
private HadoopExecutors() { }
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org