Use ThreadPool with login server.
This commit is contained in:
@@ -3656,6 +3656,19 @@ public class Config
|
||||
MYSQL_BIN_PATH = loginConfig.getString("MySqlBinLocation", "C:/xampp/mysql/bin/");
|
||||
BACKUP_PATH = loginConfig.getString("BackupPath", "../backup/");
|
||||
BACKUP_DAYS = loginConfig.getInt("BackupDays", 30);
|
||||
SCHEDULED_THREAD_POOL_COUNT = loginConfig.getInt("ScheduledThreadPoolCount", 2);
|
||||
if (SCHEDULED_THREAD_POOL_COUNT == -1)
|
||||
{
|
||||
SCHEDULED_THREAD_POOL_COUNT = Math.max(2, Runtime.getRuntime().availableProcessors() / 2);
|
||||
}
|
||||
THREADS_PER_SCHEDULED_THREAD_POOL = loginConfig.getInt("ThreadsPerScheduledThreadPool", 2);
|
||||
INSTANT_THREAD_POOL_COUNT = loginConfig.getInt("InstantThreadPoolCount", 2);
|
||||
if (INSTANT_THREAD_POOL_COUNT == -1)
|
||||
{
|
||||
INSTANT_THREAD_POOL_COUNT = Math.max(2, Runtime.getRuntime().availableProcessors() / 2);
|
||||
}
|
||||
THREADS_PER_INSTANT_THREAD_POOL = loginConfig.getInt("ThreadsPerInstantThreadPool", 4);
|
||||
THREADS_FOR_CLIENT_PACKETS = loginConfig.getBoolean("ThreadsForClientPackets", true);
|
||||
SHOW_LICENCE = loginConfig.getBoolean("ShowLicence", true);
|
||||
SHOW_PI_AGREEMENT = loginConfig.getBoolean("ShowPIAgreement", false);
|
||||
AUTO_CREATE_ACCOUNTS = loginConfig.getBoolean("AutoCreateAccounts", true);
|
||||
|
@@ -33,6 +33,7 @@ import org.l2jmobius.commons.database.DatabaseBackup;
|
||||
import org.l2jmobius.commons.database.DatabaseFactory;
|
||||
import org.l2jmobius.commons.enums.ServerMode;
|
||||
import org.l2jmobius.commons.network.NetServer;
|
||||
import org.l2jmobius.commons.threads.ThreadPool;
|
||||
import org.l2jmobius.commons.util.PropertiesParser;
|
||||
import org.l2jmobius.gameserver.network.loginserverpackets.game.ServerStatus;
|
||||
import org.l2jmobius.loginserver.network.LoginClient;
|
||||
@@ -95,6 +96,9 @@ public class LoginServer
|
||||
// Prepare Database
|
||||
DatabaseFactory.init();
|
||||
|
||||
// Initialize ThreadPool.
|
||||
ThreadPool.init();
|
||||
|
||||
try
|
||||
{
|
||||
LoginController.load();
|
||||
|
@@ -18,10 +18,11 @@ package org.l2jmobius.loginserver.network;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.network.PacketHandlerInterface;
|
||||
import org.l2jmobius.commons.network.ReadablePacket;
|
||||
import org.l2jmobius.commons.threads.ThreadPool;
|
||||
import org.l2jmobius.commons.util.CommonUtil;
|
||||
import org.l2jmobius.gameserver.network.PacketLogger;
|
||||
import org.l2jmobius.loginserver.network.clientpackets.LoginClientPacket;
|
||||
|
||||
/**
|
||||
@@ -42,8 +43,8 @@ public class LoginPacketHandler implements PacketHandlerInterface<LoginClient>
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
PacketLogger.warning("LoginPacketHandler: Problem receiving packet id from " + client);
|
||||
PacketLogger.warning(CommonUtil.getStackTrace(e));
|
||||
LOGGER.warning("LoginPacketHandler: Problem receiving packet id from " + client);
|
||||
LOGGER.warning(CommonUtil.getStackTrace(e));
|
||||
client.disconnect();
|
||||
return;
|
||||
}
|
||||
@@ -75,10 +76,23 @@ public class LoginPacketHandler implements PacketHandlerInterface<LoginClient>
|
||||
}
|
||||
|
||||
// Continue on another thread.
|
||||
final Thread thread = new Thread(new ExecuteTask(client, packet, newPacket, packetId), getClass().getName());
|
||||
thread.setPriority(Thread.NORM_PRIORITY);
|
||||
thread.setDaemon(false);
|
||||
thread.start();
|
||||
if (Config.THREADS_FOR_CLIENT_PACKETS)
|
||||
{
|
||||
ThreadPool.execute(new ExecuteTask(client, packet, newPacket, packetId));
|
||||
}
|
||||
else // Wait for execution.
|
||||
{
|
||||
try
|
||||
{
|
||||
newPacket.read(packet);
|
||||
newPacket.run(client);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.warning("LoginPacketHandler: Problem with " + client + " [Packet: 0x" + Integer.toHexString(packetId).toUpperCase() + "]");
|
||||
LOGGER.warning(CommonUtil.getStackTrace(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ExecuteTask implements Runnable
|
||||
|
Reference in New Issue
Block a user