diff --git a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer6.java b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer6.java index 2cd8b722744..e34d996a2f9 100644 --- a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer6.java +++ b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer6.java @@ -46,7 +46,20 @@ import java.util.stream.Collectors; public class ComputerPlayer6 extends ComputerPlayer /*implements Player*/ { private static final Logger logger = Logger.getLogger(ComputerPlayer6.class); - private static final ExecutorService pool = Executors.newFixedThreadPool(1); + + // same params as Executors.newFixedThreadPool + // no needs erorrs check in afterExecute here cause that pool used for FutureTask with result check already + private static final ExecutorService threadPoolSimulations = new ThreadPoolExecutor( + COMPUTER_MAX_THREADS_FOR_SIMULATIONS, + COMPUTER_MAX_THREADS_FOR_SIMULATIONS, + 0L, + TimeUnit.MILLISECONDS, + new LinkedBlockingQueue<>(), + r -> { + Thread thread = new Thread(r); + thread.setName("AI-SIM-" + thread.getId()); + return thread; + }); protected int maxDepth; protected int maxNodes; protected int maxThink; @@ -426,7 +439,7 @@ public class ComputerPlayer6 extends ComputerPlayer /*implements Player*/ { protected Integer addActionsTimed() { // run new game simulation in parallel thread FutureTask task = new FutureTask<>(() -> addActions(root, maxDepth, Integer.MIN_VALUE, Integer.MAX_VALUE)); - pool.execute(task); + threadPoolSimulations.execute(task); try { int maxSeconds = maxThink; if (COMPUTER_DISABLE_TIMEOUT_IN_GAME_SIMULATIONS) { diff --git a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java index da7e1e7ea29..167f66ffb5b 100644 --- a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java @@ -74,6 +74,8 @@ public class ComputerPlayer extends PlayerImpl implements Player { // debug only: set TRUE to debug simulation's code/games (on false sim thread will be stopped after few secs by timeout) protected boolean COMPUTER_DISABLE_TIMEOUT_IN_GAME_SIMULATIONS = false; + final static int COMPUTER_MAX_THREADS_FOR_SIMULATIONS = 1; // TODO: rework simulations logic to use multiple calcs instead one by one + private transient Map unplayable = new TreeMap<>(); private transient List playableNonInstant = new ArrayList<>(); private transient List playableInstant = new ArrayList<>();