mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-12 16:15:42 +00:00
fix[command]: std thread returns without waiting for the execution to complete.
This commit is contained in:
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);
|
||||
|
||||
Reference in new issue
Block a user