Skip to content

Commit

Permalink
Delagate thread pool shutdown to Guava MoreExecutors
Browse files Browse the repository at this point in the history
  • Loading branch information
alvasw committed Feb 5, 2023
1 parent f15a5de commit b2870cc
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
11 changes: 2 additions & 9 deletions common/src/main/java/bisq/common/util/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,9 @@ private static ThreadPoolExecutor getThreadPoolExecutor(String name,
return executor;
}

// TODO: Can some/all of the uses of this be replaced by guava MoreExecutors.shutdownAndAwaitTermination(..)?
public static void shutdownAndAwaitTermination(ExecutorService executor, long timeout, TimeUnit unit) {
executor.shutdown();
try {
if (!executor.awaitTermination(timeout, unit)) {
executor.shutdownNow();
}
} catch (InterruptedException e) {
executor.shutdownNow();
}
//noinspection UnstableApiUsage
MoreExecutors.shutdownAndAwaitTermination(executor, timeout, unit);
}

public static <V> FutureCallback<V> failureCallback(Consumer<Throwable> errorHandler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ public void shutdown() {
} catch (IOException e) {
log.error("Error closing block notification server socket", e);
} finally {
Utilities.shutdownAndAwaitTermination(executor, 1, TimeUnit.SECONDS);
Utilities.shutdownAndAwaitTermination(workerPool, 5, TimeUnit.SECONDS);
Utilities.shutdownAndAwaitTermination(executor, 2, TimeUnit.SECONDS);
Utilities.shutdownAndAwaitTermination(workerPool, 10, TimeUnit.SECONDS);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ public void shutDown() {
if (provider != null) {
provider.shutDown();
}
Utilities.shutdownAndAwaitTermination(executorService, 1, TimeUnit.SECONDS);
Utilities.shutdownAndAwaitTermination(executorService, 2, TimeUnit.SECONDS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public void shutDown() {
dataReportTimer.stop();
}

Utilities.shutdownAndAwaitTermination(executor, 2, TimeUnit.SECONDS);
Utilities.shutdownAndAwaitTermination(executor, 4, TimeUnit.SECONDS);
}

private void sendHeartBeat() {
Expand Down

0 comments on commit b2870cc

Please sign in to comment.