Skip to content

Commit

Permalink
* executor: tweak shutdown handling, print all tasks not complete
Browse files Browse the repository at this point in the history
Signed-off-by: neo <1100909+neowu@users.noreply.github.com>
  • Loading branch information
neowu committed Feb 7, 2024
1 parent ec1f94d commit 45f5a86
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import core.framework.async.Task;
import core.framework.internal.log.ActionLog;
import core.framework.internal.log.LogManager;
import core.framework.util.Sets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -12,7 +13,6 @@
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.RejectedExecutionException;
Expand All @@ -31,7 +31,7 @@ public final class ExecutorImpl implements Executor {
private final LogManager logManager;
private final long maxProcessTimeInNano;
private final ReentrantLock lock = new ReentrantLock();
private final Set<String> runningTasks = ConcurrentHashMap.newKeySet(); // track running tasks, used to print tasks failed to complete on shutdown
private final Set<String> runningTasks = Sets.newConcurrentHashSet(); // track running tasks, used to print tasks failed to complete on shutdown

volatile ScheduledExecutorService scheduler;

Expand Down Expand Up @@ -61,10 +61,11 @@ public void awaitTermination(long timeoutInMs) throws InterruptedException {
boolean success = executor.awaitTermination(timeoutInMs, TimeUnit.MILLISECONDS);
if (!success) {
executor.shutdownNow();
logger.warn(errorCode("FAILED_TO_STOP"), "failed to terminate executor, canceledTasks={}", runningTasks);
} else {
logger.info("executor stopped");
if (!runningTasks.isEmpty()) {
logger.error(errorCode("FAILED_TO_STOP"), "failed to terminate executor, canceledTasks={}", runningTasks);
}
}
logger.info("executor stopped");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static String abbreviateLoggerName(String name) {
for (int i = 0; i < tokens.length; i++) {
String token = tokens[i];
if (i > 0) builder.append('.');
if (i < abbrCount && token.length() >= 1) {
if (i < abbrCount && !token.isEmpty()) {
builder.append(token.charAt(0));
} else {
builder.append(token);
Expand Down

0 comments on commit 45f5a86

Please sign in to comment.