fix[command]: std thread returns without waiting for the execution to complete.

This commit is contained in:
jaysunxiao committed 2026-03-15 09:50:58 +08:00
1 parent fbb9e48282
commit 7e2108c8c4
2 files changed
+25 -29

No files matched your search

@@ -18,10 +18,7 @@ import io.netty.util.concurrent.EventExecutorGroup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;
/**
* @author godotg
@@ -108,6 +105,22 @@ public abstract class ThreadUtils {
};
}
public static <T> Callable<T> safeCallable(Callable<T> callable) {
return new Callable<T>() {
@Override
public T call() {
try {
return callable.call();
} catch (Exception e) {
logger.error("unknown exception", e);
} catch (Throwable t) {
logger.error("unknown error", t);
}
return null;
}
};
}
// -----------------------------------------------------------------------------------------------------------------
// threadId -> (Thread, Executor)
private static final CopyOnWriteHashMapLongObject<Pair<Thread, Executor>> threadExecutorMap = new CopyOnWriteHashMapLongObject<>(Runtime.getRuntime().availableProcessors() * 8);