feat[executor]:add method to get executor based on hash

This commit is contained in:
luca
2024-06-26 14:18:24 +08:00
parent f48e977283
commit 3d80c13c29
2 changed files with 10 additions and 0 deletions
@@ -29,11 +29,13 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.function.Supplier;
/**
* @author godotg
@@ -151,6 +153,10 @@ public abstract class EventBus {
receiverMap.computeIfAbsent(eventType, it -> new ArrayList<>(1)).add(receiver);
}
public static ExecutorService getExecutor(int executorHash){
return executors[Math.abs(executorHash % EXECUTORS_SIZE)];
}
}
@@ -123,4 +123,8 @@ public final class TaskBus {
return executor;
}
public static ExecutorService getExecutor(int hash){
return executors[calTaskExecutorIndex(hash)];
}
}