Merge pull request #6560 from alvasw/delegate_thread_pool_shutdown_to_guava

Delagate thread pool shutdown to Guava MoreExecutors
This commit is contained in:
Alejandro García 2023-02-05 22:40:14 +00:00 committed by GitHub
commit 882afc1ff3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 13 deletions

View File

@ -178,16 +178,9 @@ public class Utilities {
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) {

View File

@ -110,8 +110,8 @@ public class BitcoindDaemon {
} 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);
}
}

View File

@ -78,6 +78,6 @@ public class PriceRequest {
if (provider != null) {
provider.shutDown();
}
Utilities.shutdownAndAwaitTermination(executorService, 1, TimeUnit.SECONDS);
Utilities.shutdownAndAwaitTermination(executorService, 2, TimeUnit.SECONDS);
}
}

View File

@ -263,7 +263,7 @@ public class SeedNodeReportingService {
dataReportTimer.stop();
}
Utilities.shutdownAndAwaitTermination(executor, 2, TimeUnit.SECONDS);
Utilities.shutdownAndAwaitTermination(executor, 4, TimeUnit.SECONDS);
}
private void sendHeartBeat() {