use Task class so that exception is handled with currently registered DefaultUncaughtExceptionHandler, fixes no log issue

master
melvinzhang 2015-06-08 10:56:15 +08:00
parent 54ec11e13b
commit 179f64369d
2 changed files with 5 additions and 11 deletions

View File

@ -7,7 +7,6 @@ import magic.model.MagicGameLog;
import magic.model.MagicPlayer;
import magic.model.choice.MagicBuilderPayManaCostResult;
import magic.model.event.MagicEvent;
import magic.exception.handler.ConsoleExceptionHandler;
import java.util.ArrayList;
import java.util.Collections;
@ -136,7 +135,6 @@ public class MCTSAI implements MagicAI {
log("MCTS cached=" + root.getNumSim());
sims = 0;
final ConsoleExceptionHandler handler = new ConsoleExceptionHandler();
final ExecutorService executor = Executors.newFixedThreadPool(THREADS);
final BlockingQueue<Runnable> queue = new LinkedBlockingQueue<>();
@ -144,14 +142,10 @@ public class MCTSAI implements MagicAI {
final int aiLevel = scorePlayer.getAiProfile().getAiLevel();
final long START_TIME = System.currentTimeMillis();
final long END_TIME = START_TIME + 1000 * aiLevel;
final Runnable updateTask = new Runnable() {
final Runnable updateTask = new Task() {
@Override
public void run() {
try {
TreeUpdate(this, root, aiGame, executor, queue, END_TIME);
} catch (final Throwable ex) {
handler.uncaughtException(Thread.currentThread(), ex);
}
public void execute() {
TreeUpdate(this, root, aiGame, executor, queue, END_TIME);
}
};

View File

@ -79,9 +79,9 @@ public class MMAB implements MagicAI {
workerGame.setFastTarget(true);
workerGame.setFastBlocker(true);
executor.execute(new Runnable() {
executor.execute(new Task() {
@Override
public void run() {
public void execute() {
final MMABWorker worker=new MMABWorker(
Thread.currentThread().getId(),
workerGame,