Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delagate thread pool shutdown to Guava MoreExecutors #6560

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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