mirror of
https://github.com/wassname/ray.git
synced 2026-06-28 02:30:45 +08:00
fix java UT about multi-threading (#8014)
This commit is contained in:
@@ -36,6 +36,7 @@ import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -227,21 +228,27 @@ public class LocalModeTaskSubmitter implements TaskSubmitter {
|
||||
|
||||
if (unreadyObjects.isEmpty()) {
|
||||
// If all dependencies are ready, execute this task.
|
||||
ExecutorService executorService;
|
||||
if (taskSpec.getType() == TaskType.ACTOR_CREATION_TASK) {
|
||||
ExecutorService actorExecutorService = Executors.newSingleThreadExecutor();
|
||||
executorService = Executors.newSingleThreadExecutor();
|
||||
synchronized (actorTaskExecutorServices) {
|
||||
actorTaskExecutorServices.put(getActorId(taskSpec), actorExecutorService);
|
||||
actorTaskExecutorServices.put(getActorId(taskSpec), executorService);
|
||||
}
|
||||
actorExecutorService.submit(runnable);
|
||||
} else if (taskSpec.getType() == TaskType.ACTOR_TASK) {
|
||||
synchronized (actorTaskExecutorServices) {
|
||||
ExecutorService actorExecutorService =
|
||||
actorTaskExecutorServices.get(getActorId(taskSpec));
|
||||
actorExecutorService.submit(runnable);
|
||||
executorService = actorTaskExecutorServices.get(getActorId(taskSpec));
|
||||
}
|
||||
} else {
|
||||
// Normal task.
|
||||
normalTaskExecutorService.submit(runnable);
|
||||
executorService = normalTaskExecutorService;
|
||||
}
|
||||
try {
|
||||
executorService.submit(runnable);
|
||||
} catch (RejectedExecutionException e) {
|
||||
if (executorService.isShutdown()) {
|
||||
LOGGER.warn("Ignore task submission due to the ExecutorService is shutdown. Task: {}",
|
||||
taskSpec);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If some dependencies aren't ready yet, put this task in waiting list.
|
||||
|
||||
Reference in New Issue
Block a user