mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
Fixed thread pool leak and work queue growing.
This commit is contained in:
parent
c7ae032d5a
commit
cfa779661d
5 changed files with 24 additions and 4 deletions
|
@ -32,6 +32,7 @@ import java.rmi.RemoteException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import mage.game.draft.Draft;
|
import mage.game.draft.Draft;
|
||||||
|
@ -142,6 +143,7 @@ public class DraftSession {
|
||||||
private synchronized void cancelTimeout() {
|
private synchronized void cancelTimeout() {
|
||||||
if (futureTimeout != null) {
|
if (futureTimeout != null) {
|
||||||
futureTimeout.cancel(false);
|
futureTimeout.cancel(false);
|
||||||
|
((ThreadPoolExecutor)timeoutExecutor).getQueue().remove(futureTimeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -278,7 +278,8 @@ public class GameController implements GameCallback {
|
||||||
|
|
||||||
public void kill(UUID sessionId) {
|
public void kill(UUID sessionId) {
|
||||||
if (sessionPlayerMap.containsKey(sessionId)) {
|
if (sessionPlayerMap.containsKey(sessionId)) {
|
||||||
gameSessions.get(sessionPlayerMap.get(sessionId)).setKilled();
|
GameSession session = gameSessions.get(sessionPlayerMap.get(sessionId));
|
||||||
|
session.destroy();
|
||||||
gameSessions.remove(sessionPlayerMap.get(sessionId));
|
gameSessions.remove(sessionPlayerMap.get(sessionId));
|
||||||
leave(sessionId);
|
leave(sessionId);
|
||||||
sessionPlayerMap.remove(sessionId);
|
sessionPlayerMap.remove(sessionId);
|
||||||
|
|
|
@ -34,6 +34,7 @@ import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.MageException;
|
import mage.MageException;
|
||||||
|
@ -172,6 +173,8 @@ public class GameSession extends GameWatcher {
|
||||||
private synchronized void cancelTimeout() {
|
private synchronized void cancelTimeout() {
|
||||||
if (futureTimeout != null) {
|
if (futureTimeout != null) {
|
||||||
futureTimeout.cancel(false);
|
futureTimeout.cancel(false);
|
||||||
|
((ThreadPoolExecutor)timeoutExecutor).getQueue().remove(futureTimeout);
|
||||||
|
//System.out.println("tasks:"+ ((ThreadPoolExecutor)timeoutExecutor).getTaskCount());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,4 +197,9 @@ public class GameSession extends GameWatcher {
|
||||||
cancelTimeout();
|
cancelTimeout();
|
||||||
game.getPlayer(playerId).setResponseInteger(data);
|
game.getPlayer(playerId).setResponseInteger(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void destroy() {
|
||||||
|
cancelTimeout();
|
||||||
|
setKilled();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ import java.rmi.RemoteException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import mage.cards.decks.Deck;
|
import mage.cards.decks.Deck;
|
||||||
|
@ -146,6 +147,7 @@ public class TournamentSession {
|
||||||
private synchronized void cancelTimeout() {
|
private synchronized void cancelTimeout() {
|
||||||
if (futureTimeout != null) {
|
if (futureTimeout != null) {
|
||||||
futureTimeout.cancel(false);
|
futureTimeout.cancel(false);
|
||||||
|
((ThreadPoolExecutor)timeoutExecutor).getQueue().remove(futureTimeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,9 +28,7 @@
|
||||||
|
|
||||||
package mage.server.util;
|
package mage.server.util;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -42,6 +40,15 @@ public class ThreadExecutor {
|
||||||
private static ExecutorService gameExecutor = Executors.newFixedThreadPool(ConfigSettings.getInstance().getMaxGameThreads());
|
private static ExecutorService gameExecutor = Executors.newFixedThreadPool(ConfigSettings.getInstance().getMaxGameThreads());
|
||||||
private static ScheduledExecutorService timeoutExecutor = Executors.newScheduledThreadPool(5);
|
private static ScheduledExecutorService timeoutExecutor = Executors.newScheduledThreadPool(5);
|
||||||
|
|
||||||
|
static {
|
||||||
|
((ThreadPoolExecutor)rmiExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||||
|
((ThreadPoolExecutor)rmiExecutor).allowCoreThreadTimeOut(true);
|
||||||
|
((ThreadPoolExecutor)gameExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||||
|
((ThreadPoolExecutor)gameExecutor).allowCoreThreadTimeOut(true);
|
||||||
|
((ThreadPoolExecutor)timeoutExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||||
|
((ThreadPoolExecutor)timeoutExecutor).allowCoreThreadTimeOut(true);
|
||||||
|
}
|
||||||
|
|
||||||
private final static ThreadExecutor INSTANCE = new ThreadExecutor();
|
private final static ThreadExecutor INSTANCE = new ThreadExecutor();
|
||||||
|
|
||||||
public static ThreadExecutor getInstance() {
|
public static ThreadExecutor getInstance() {
|
||||||
|
|
Loading…
Reference in a new issue