ctubbsii commented on a change in pull request #1818:
URL: https://github.com/apache/accumulo/pull/1818#discussion_r543498123
##########
File path:
core/src/main/java/org/apache/accumulo/core/util/cleaner/CleanerUtil.java
##########
@@ -107,10 +107,14 @@ public static Cleanable shutdownThreadPoolExecutor(Object
tpe, Logger log) {
requireNonNull(tpe);
requireNonNull(log);
return CLEANER.register(tpe, () -> {
+ ThreadPoolExecutor pool = (ThreadPoolExecutor) tpe;
Review comment:
Why cast here? Why not just make the type more restrictive in the method
signature 4 lines above?
##########
File path:
core/src/main/java/org/apache/accumulo/core/clientImpl/TabletServerBatchReader.java
##########
@@ -72,16 +72,15 @@ protected TabletServerBatchReader(ClientContext context,
Class<?> scopeClass, Ta
queryThreadPool = ThreadPools.getFixedThreadPool(numQueryThreads,
"batch scanner " + batchReaderInstance + "-", false);
+ // Call shutdown on this thread pool in case the caller does not call
close().
cleanable = CleanerUtil.shutdownThreadPoolExecutor(queryThreadPool, log);
}
@Override
public void close() {
if (closed.compareAndSet(false, true)) {
- // deregister cleanable, but it won't run because it checks
- // the value of closed first, which is now true
- cleanable.clean();
queryThreadPool.shutdownNow();
+ cleanable.clean();
Review comment:
We really should deregister the cleanable first, so we don't get
duplicate exceptions from that if there's a problem calling the shutdown.
##########
File path:
core/src/main/java/org/apache/accumulo/core/util/cleaner/CleanerUtil.java
##########
@@ -107,10 +107,14 @@ public static Cleanable shutdownThreadPoolExecutor(Object
tpe, Logger log) {
requireNonNull(tpe);
requireNonNull(log);
return CLEANER.register(tpe, () -> {
+ ThreadPoolExecutor pool = (ThreadPoolExecutor) tpe;
+ if (pool.isShutdown()) {
+ return;
+ }
Review comment:
The other cleanables pass in the closed atomic boolean, so they can
detect whether the resource has already been closed, and the cleanable action
isn't needed. I suggest following the same pattern, just for convenience,
rather than follow a custom pattern here.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]