mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-03 05:20:50 +00:00
perf[executor]: add method to get executor based on hash
This commit is contained in:
1 parent
4729085900
commit
b591864c03
2 files changed
+12
-14
No files matched your search
@@ -106,25 +106,25 @@ public final class TaskBus {
|
||||
}
|
||||
|
||||
public static void execute(int taskExecutorHash, Runnable runnable) {
|
||||
executors[calTaskExecutorIndex(taskExecutorHash)].execute(ThreadUtils.safeRunnable(runnable));
|
||||
executorOf(taskExecutorHash).execute(ThreadUtils.safeRunnable(runnable));
|
||||
}
|
||||
|
||||
public static void execute(Object argument, Runnable runnable) {
|
||||
execute(calTaskExecutorHash(argument), runnable);
|
||||
}
|
||||
|
||||
public static ExecutorService executorOf(int hash){
|
||||
return executors[calTaskExecutorIndex(hash)];
|
||||
}
|
||||
|
||||
// 在task,event,scheduler线程执行的异步请求,请求成功过后依然在相同的线程执行回调任务
|
||||
public static Executor currentThreadExecutor() {
|
||||
var threadId = Thread.currentThread().getId();
|
||||
var executor = ThreadUtils.executorByThreadId(threadId);
|
||||
if (executor == null) {
|
||||
return executors[calTaskExecutorIndex(RandomUtils.randomInt())];
|
||||
return executorOf(RandomUtils.randomInt());
|
||||
}
|
||||
return executor;
|
||||
}
|
||||
|
||||
public static ExecutorService getExecutor(int hash){
|
||||
return executors[calTaskExecutorIndex(hash)];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user