aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/concurrent
diff options
context:
space:
mode:
authorGravatar Nathan Harmata <nharmata@google.com>2016-11-17 22:37:33 +0000
committerGravatar Yun Peng <pcloudy@google.com>2016-11-18 10:54:37 +0000
commita2565aa2b33273972554325a02f2a9bc30a15c62 (patch)
tree3fdb183d74305464a1d59db202186689669e4bad /src/main/java/com/google/devtools/build/lib/concurrent
parent621212d09e000773c7c63b7bf7ce0a4e89aad29b (diff)
Introduce a failFast mode to OutputFormatterCallback#close.
-- MOS_MIGRATED_REVID=139508838
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/concurrent')
-rw-r--r--src/main/java/com/google/devtools/build/lib/concurrent/ExecutorUtil.java37
1 files changed, 29 insertions, 8 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/concurrent/ExecutorUtil.java b/src/main/java/com/google/devtools/build/lib/concurrent/ExecutorUtil.java
index 1a5a7720df..07ca266aaa 100644
--- a/src/main/java/com/google/devtools/build/lib/concurrent/ExecutorUtil.java
+++ b/src/main/java/com/google/devtools/build/lib/concurrent/ExecutorUtil.java
@@ -31,30 +31,51 @@ public class ExecutorUtil {
}
/**
- * Shutdown the executor. If an interrupt occurs, invoke shutdownNow(), but
+ * Shutdown the executor via shutdownNow(). If an interrupt occurs, ignore it (since the tasks
+ * were already interrupted by the initial shutdownNow) and still block on the eventual
+ * termination of the pool.
+ *
+ * @param executor the executor service.
+ * @return true iff interrupted.
+ */
+ public static boolean uninterruptibleShutdownNow(ExecutorService executor) {
+ return shutdownImpl(executor, /*shutdownNowInitially=*/true, /*shutdownNowOnInterrupt=*/false);
+ }
+
+ /**
+ * Shutdown the executor via shutdown(). If an interrupt occurs, invoke shutdownNow(), but
* still block on the eventual termination of the pool.
*
* @param executor the executor service.
* @return true iff interrupted.
*/
public static boolean interruptibleShutdown(ExecutorService executor) {
- return shutdownImpl(executor, /*interruptible=*/true);
+ return shutdownImpl(
+ executor,
+ /*shutdownNowInitially=*/false,
+ /*shutdownNowOnInterrupt=*/true);
}
/**
- * Shutdown the executor. If an interrupt occurs, ignore it and still block on the eventual
- * termination of the pool. This way, all tasks are guaranteed to have completed normally.
+ * Shutdown the executor via shutdown(). If an interrupt occurs, ignore it and still block on the
+ * eventual termination of the pool. This way, all tasks are guaranteed to have completed
+ * normally.
*
* @param executor the executor service.
* @return true iff interrupted.
*/
public static boolean uninterruptibleShutdown(ExecutorService executor) {
- return shutdownImpl(executor, /*interruptible=*/false);
+ return shutdownImpl(executor, /*shutdownNowInitially=*/false, /*shutdownNowOnInterrupt=*/false);
}
- private static boolean shutdownImpl(ExecutorService executor, boolean interruptible) {
+ private static boolean shutdownImpl(
+ ExecutorService executor, boolean shutdownNowInitially, boolean shutdownNowOnInterrupt) {
Preconditions.checkState(!executor.isShutdown());
- executor.shutdown();
+ if (shutdownNowInitially) {
+ executor.shutdownNow();
+ } else {
+ executor.shutdown();
+ }
// Common pattern: check for interrupt, but don't return until all threads
// are finished.
@@ -64,7 +85,7 @@ public class ExecutorUtil {
executor.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
break;
} catch (InterruptedException e) {
- if (interruptible) {
+ if (shutdownNowOnInterrupt) {
executor.shutdownNow();
}
interrupted = true;