Przeglądaj źródła

DeadLockDetector config options, cleaning and yes, turning it ON ;)
Thanks Nickolbas, GodKratos

Sami 16 lat temu
rodzic
commit
d1520a581d

+ 4 - 1
L2_GameServer/java/config/General.properties

@@ -140,8 +140,11 @@ AiMaxThread = 6
 PacketLifeTime = 0
 
 #Dead Lock Detector (a separate thread for detecting deadlocks)
-#for improved crash logs and automatic restart in deadlock case (default behavior)
+#For improved crash logs and automatic restart in deadlock case if enabled
+#Check interval is in seconds
 DeadLockDetector = False
+DeadLockCheckInterval = 20
+RestartOnDeadlock = False
 
 #============================================================#
 #                         Optimize                           #

+ 4 - 0
L2_GameServer/java/net/sf/l2j/Config.java

@@ -346,6 +346,8 @@ public final class Config
     public static int		AI_MAX_THREAD;
     public static int		PACKET_LIFETIME;
     public static boolean	DEADLOCK_DETECTOR;
+    public static int		DEADLOCK_CHECK_INTERVAL;
+    public static boolean	RESTART_ON_DEADLOCK;
     public static int		FLOODPROTECTOR_INITIALSIZE;
     public static boolean	ALLOW_DISCARDITEM;
     public static int		AUTODESTROY_ITEM_AFTER;
@@ -1409,6 +1411,8 @@ public final class Config
                 AI_MAX_THREAD								= Integer.parseInt(General.getProperty("AiMaxThread", "10"));
                 PACKET_LIFETIME								= Integer.parseInt(General.getProperty("PacketLifeTime", "0"));
                 DEADLOCK_DETECTOR							= Boolean.parseBoolean(General.getProperty("DeadLockDetector", "False"));
+                DEADLOCK_CHECK_INTERVAL						= Integer.parseInt(General.getProperty("DeadLockCheckInterval", "20"));
+                RESTART_ON_DEADLOCK							= Boolean.parseBoolean(General.getProperty("RestartOnDeadlock", "False"));
                 FLOODPROTECTOR_INITIALSIZE					= Integer.parseInt(General.getProperty("FloodProtectorInitialSize", "50"));
                 ALLOW_DISCARDITEM							= Boolean.parseBoolean(General.getProperty("AllowDiscardItem", "True"));
                 AUTODESTROY_ITEM_AFTER						= Integer.parseInt(General.getProperty("AutoDestroyDroppedItemAfter", "0"));

+ 5 - 1
L2_GameServer/java/net/sf/l2j/gameserver/GameServer.java

@@ -450,7 +450,11 @@ public class GameServer
 		TvTManager.getInstance();
 		KnownListUpdateTaskManager.getInstance();
 		if (Config.DEADLOCK_DETECTOR)
-			_deadDetectThread = new DeadLockDetector(20, DeadLockDetector.RESTART);
+		{
+			_deadDetectThread = new DeadLockDetector();
+			_deadDetectThread.setDaemon(true);
+			_deadDetectThread.start();
+		}
 		else
 			_deadDetectThread = null;
 		System.gc();

+ 0 - 2
L2_GameServer/java/net/sf/l2j/gameserver/Shutdown.java

@@ -209,8 +209,6 @@ public class Shutdown extends Thread
 			try
 			{
 				GameTimeController.getInstance().stopTimer();
-				if (Config.DEADLOCK_DETECTOR)
-					GameServer.gameServer.getDeadLockDetectorThread().interrupt();
 			}
 			catch (Throwable t)
 			{

+ 5 - 21
L2_GameServer/java/net/sf/l2j/util/DeadLockDetector.java

@@ -22,6 +22,7 @@ import java.lang.management.ThreadMXBean;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import net.sf.l2j.Config;
 import net.sf.l2j.gameserver.Shutdown;
 import net.sf.l2j.gameserver.Announcements;
 
@@ -33,28 +34,21 @@ public class DeadLockDetector extends Thread
 {
 	private static Logger _log = Logger.getLogger(DeadLockDetector.class.getName());
 
-	public static final byte NOTHING = 0;
-	public static final byte RESTART = 1;
-	public static final byte REPAIR = 2;
-
-	private final int _sleepTime;
+	private static final int _sleepTime = Config.DEADLOCK_CHECK_INTERVAL*1000;
 
 	private final ThreadMXBean tmx;
 
-	private final byte _doWhenDL;
-	public DeadLockDetector(int sleepTime, byte doWhenDL)
+	public DeadLockDetector()
 	{
 		super("DeadLockDetector");
-		_sleepTime = sleepTime*1000;
 		tmx = ManagementFactory.getThreadMXBean();
-		_doWhenDL = doWhenDL;
 	}
 
 	@Override 
 	public final void run()
 	{
 		boolean deadlock = false;
-		while(!deadlock && !this.isInterrupted())
+		while(!deadlock)
 		{
 			try
 			{
@@ -89,13 +83,7 @@ public class DeadLockDetector extends Thread
 					}
 					_log.warning(info);
 
-					if(_doWhenDL == RESTART)
-					{
-						Announcements an = Announcements.getInstance();
-						an.announceToAll("Server has stability issues - restarting now.");
-						Shutdown.getInstance().startTelnetShutdown("DeadLockDetector - Auto Restart",60,true);
-					}
-					else if(_doWhenDL == REPAIR)
+					if(Config.RESTART_ON_DEADLOCK)
 					{
 						Announcements an = Announcements.getInstance();
 						an.announceToAll("Server has stability issues - restarting now.");
@@ -105,10 +93,6 @@ public class DeadLockDetector extends Thread
 				}
 				Thread.sleep(_sleepTime); 
 			}
-			catch(InterruptedException e)
-			{
-				//
-			}
 			catch(Exception e)
 			{
 				_log.log(Level.WARNING,"DeadLockDetector: ",e);