diff --git a/L2J_Mobius_1.0_Ertheia/dist/game/config/Server.ini b/L2J_Mobius_1.0_Ertheia/dist/game/config/Server.ini index fcc866a536..32f67daca1 100644 --- a/L2J_Mobius_1.0_Ertheia/dist/game/config/Server.ini +++ b/L2J_Mobius_1.0_Ertheia/dist/game/config/Server.ini @@ -145,6 +145,10 @@ ThreadsPerInstantThreadPool = 2 # Default: 2 UrgentPacketThreadCoreSize = 2 +# Use threads to decrease startup time. +# Default: False +ThreadsForLoading = False + # --------------------------------------------------------------------------- # Dead Lock Detector (separate thread for detecting deadlocks) diff --git a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/Config.java b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/Config.java index d368554cf5..6ac7132124 100644 --- a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/Config.java +++ b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/Config.java @@ -430,6 +430,7 @@ public final class Config public static int INSTANT_THREAD_POOL_COUNT; public static int THREADS_PER_INSTANT_THREAD_POOL; public static int IO_PACKET_THREAD_CORE_SIZE; + public static boolean THREADS_FOR_LOADING; public static boolean DEADLOCK_DETECTOR; public static int DEADLOCK_CHECK_INTERVAL; public static boolean RESTART_ON_DEADLOCK; @@ -1284,6 +1285,7 @@ public final class Config } THREADS_PER_INSTANT_THREAD_POOL = serverSettings.getInt("ThreadsPerInstantThreadPool", 2); IO_PACKET_THREAD_CORE_SIZE = serverSettings.getInt("UrgentPacketThreadCoreSize", 2); + THREADS_FOR_LOADING = serverSettings.getBoolean("ThreadsForLoading", false); DEADLOCK_DETECTOR = serverSettings.getBoolean("DeadLockDetector", true); DEADLOCK_CHECK_INTERVAL = serverSettings.getInt("DeadLockCheckInterval", 20); diff --git a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/commons/util/IXmlReader.java b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/commons/util/IXmlReader.java index 4bfed2396e..54bb8b3292 100644 --- a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/commons/util/IXmlReader.java +++ b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/commons/util/IXmlReader.java @@ -165,29 +165,47 @@ public interface IXmlReader return false; } - final List> jobs = new CopyOnWriteArrayList<>(); - final File[] listOfFiles = dir.listFiles(); - for (File f : listOfFiles) + if (Config.THREADS_FOR_LOADING) { - if (recursive && f.isDirectory()) + final List> jobs = new CopyOnWriteArrayList<>(); + final File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { - parseDirectory(f, recursive); - } - else if (getCurrentFileFilter().accept(f)) - { - jobs.add(ThreadPool.schedule(() -> + if (recursive && file.isDirectory()) { - parseFile(f); - }, 0)); + parseDirectory(file, recursive); + } + else if (getCurrentFileFilter().accept(file)) + { + jobs.add(ThreadPool.schedule(() -> + { + parseFile(file); + }, 0)); + } + } + while (!jobs.isEmpty()) + { + for (ScheduledFuture job : jobs) + { + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } + } } } - while (!jobs.isEmpty()) + else { - for (ScheduledFuture job : jobs) + final File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { - if ((job == null) || job.isDone() || job.isCancelled()) + if (recursive && file.isDirectory()) { - jobs.remove(job); + parseDirectory(file, recursive); + } + else if (getCurrentFileFilter().accept(file)) + { + parseFile(file); } } } diff --git a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java index 806d00902a..10ae6bca06 100644 --- a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java +++ b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java @@ -95,28 +95,44 @@ public class SpawnsData implements IXmlReader } LOGGER.info(getClass().getSimpleName() + ": Initializing spawns..."); - final List> jobs = new CopyOnWriteArrayList<>(); - for (SpawnTemplate template : _spawns) + + if (Config.THREADS_FOR_LOADING) { - if (template.isSpawningByDefault()) + final List> jobs = new CopyOnWriteArrayList<>(); + for (SpawnTemplate template : _spawns) { - jobs.add(ThreadPool.schedule(() -> + if (template.isSpawningByDefault()) { - template.spawnAll(null); - template.notifyActivate(); - }, 0)); + jobs.add(ThreadPool.schedule(() -> + { + template.spawnAll(null); + template.notifyActivate(); + }, 0)); + } } - } - while (!jobs.isEmpty()) - { - for (ScheduledFuture job : jobs) + while (!jobs.isEmpty()) { - if ((job == null) || job.isDone() || job.isCancelled()) + for (ScheduledFuture job : jobs) { - jobs.remove(job); + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } } } } + else + { + for (SpawnTemplate template : _spawns) + { + if (template.isSpawningByDefault()) + { + template.spawnAll(null); + template.notifyActivate(); + } + } + } + LOGGER.info(getClass().getSimpleName() + ": All spawns has been initialized!"); } diff --git a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/engines/DocumentEngine.java b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/engines/DocumentEngine.java index 10f04f4fb3..68302f92da 100644 --- a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/engines/DocumentEngine.java +++ b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/engines/DocumentEngine.java @@ -69,26 +69,40 @@ public class DocumentEngine public List loadItems() { final List list = new CopyOnWriteArrayList<>(); - final List> jobs = new CopyOnWriteArrayList<>(); - for (File file : _itemFiles) + + if (Config.THREADS_FOR_LOADING) { - jobs.add(ThreadPool.schedule(() -> + final List> jobs = new CopyOnWriteArrayList<>(); + for (File file : _itemFiles) + { + jobs.add(ThreadPool.schedule(() -> + { + final DocumentItem document = new DocumentItem(file); + document.parse(); + list.addAll(document.getItemList()); + }, 0)); + } + while (!jobs.isEmpty()) + { + for (ScheduledFuture job : jobs) + { + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } + } + } + } + else + { + for (File file : _itemFiles) { final DocumentItem document = new DocumentItem(file); document.parse(); list.addAll(document.getItemList()); - }, 0)); - } - while (!jobs.isEmpty()) - { - for (ScheduledFuture job : jobs) - { - if ((job == null) || job.isDone() || job.isCancelled()) - { - jobs.remove(job); - } } } + return list; } diff --git a/L2J_Mobius_2.5_Underground/dist/game/config/Server.ini b/L2J_Mobius_2.5_Underground/dist/game/config/Server.ini index e6403d4f48..a392acdde1 100644 --- a/L2J_Mobius_2.5_Underground/dist/game/config/Server.ini +++ b/L2J_Mobius_2.5_Underground/dist/game/config/Server.ini @@ -145,6 +145,10 @@ ThreadsPerInstantThreadPool = 2 # Default: 2 UrgentPacketThreadCoreSize = 2 +# Use threads to decrease startup time. +# Default: False +ThreadsForLoading = False + # --------------------------------------------------------------------------- # Dead Lock Detector (separate thread for detecting deadlocks) diff --git a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/Config.java b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/Config.java index dcea4128f1..6aa7f95979 100644 --- a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/Config.java +++ b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/Config.java @@ -436,6 +436,7 @@ public final class Config public static int INSTANT_THREAD_POOL_COUNT; public static int THREADS_PER_INSTANT_THREAD_POOL; public static int IO_PACKET_THREAD_CORE_SIZE; + public static boolean THREADS_FOR_LOADING; public static boolean DEADLOCK_DETECTOR; public static int DEADLOCK_CHECK_INTERVAL; public static boolean RESTART_ON_DEADLOCK; @@ -1291,6 +1292,7 @@ public final class Config } THREADS_PER_INSTANT_THREAD_POOL = serverSettings.getInt("ThreadsPerInstantThreadPool", 2); IO_PACKET_THREAD_CORE_SIZE = serverSettings.getInt("UrgentPacketThreadCoreSize", 2); + THREADS_FOR_LOADING = serverSettings.getBoolean("ThreadsForLoading", false); DEADLOCK_DETECTOR = serverSettings.getBoolean("DeadLockDetector", true); DEADLOCK_CHECK_INTERVAL = serverSettings.getInt("DeadLockCheckInterval", 20); diff --git a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/commons/util/IXmlReader.java b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/commons/util/IXmlReader.java index 4bfed2396e..54bb8b3292 100644 --- a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/commons/util/IXmlReader.java +++ b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/commons/util/IXmlReader.java @@ -165,29 +165,47 @@ public interface IXmlReader return false; } - final List> jobs = new CopyOnWriteArrayList<>(); - final File[] listOfFiles = dir.listFiles(); - for (File f : listOfFiles) + if (Config.THREADS_FOR_LOADING) { - if (recursive && f.isDirectory()) + final List> jobs = new CopyOnWriteArrayList<>(); + final File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { - parseDirectory(f, recursive); - } - else if (getCurrentFileFilter().accept(f)) - { - jobs.add(ThreadPool.schedule(() -> + if (recursive && file.isDirectory()) { - parseFile(f); - }, 0)); + parseDirectory(file, recursive); + } + else if (getCurrentFileFilter().accept(file)) + { + jobs.add(ThreadPool.schedule(() -> + { + parseFile(file); + }, 0)); + } + } + while (!jobs.isEmpty()) + { + for (ScheduledFuture job : jobs) + { + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } + } } } - while (!jobs.isEmpty()) + else { - for (ScheduledFuture job : jobs) + final File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { - if ((job == null) || job.isDone() || job.isCancelled()) + if (recursive && file.isDirectory()) { - jobs.remove(job); + parseDirectory(file, recursive); + } + else if (getCurrentFileFilter().accept(file)) + { + parseFile(file); } } } diff --git a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java index 806d00902a..10ae6bca06 100644 --- a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java +++ b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java @@ -95,28 +95,44 @@ public class SpawnsData implements IXmlReader } LOGGER.info(getClass().getSimpleName() + ": Initializing spawns..."); - final List> jobs = new CopyOnWriteArrayList<>(); - for (SpawnTemplate template : _spawns) + + if (Config.THREADS_FOR_LOADING) { - if (template.isSpawningByDefault()) + final List> jobs = new CopyOnWriteArrayList<>(); + for (SpawnTemplate template : _spawns) { - jobs.add(ThreadPool.schedule(() -> + if (template.isSpawningByDefault()) { - template.spawnAll(null); - template.notifyActivate(); - }, 0)); + jobs.add(ThreadPool.schedule(() -> + { + template.spawnAll(null); + template.notifyActivate(); + }, 0)); + } } - } - while (!jobs.isEmpty()) - { - for (ScheduledFuture job : jobs) + while (!jobs.isEmpty()) { - if ((job == null) || job.isDone() || job.isCancelled()) + for (ScheduledFuture job : jobs) { - jobs.remove(job); + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } } } } + else + { + for (SpawnTemplate template : _spawns) + { + if (template.isSpawningByDefault()) + { + template.spawnAll(null); + template.notifyActivate(); + } + } + } + LOGGER.info(getClass().getSimpleName() + ": All spawns has been initialized!"); } diff --git a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/engines/DocumentEngine.java b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/engines/DocumentEngine.java index 10f04f4fb3..68302f92da 100644 --- a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/engines/DocumentEngine.java +++ b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/engines/DocumentEngine.java @@ -69,26 +69,40 @@ public class DocumentEngine public List loadItems() { final List list = new CopyOnWriteArrayList<>(); - final List> jobs = new CopyOnWriteArrayList<>(); - for (File file : _itemFiles) + + if (Config.THREADS_FOR_LOADING) { - jobs.add(ThreadPool.schedule(() -> + final List> jobs = new CopyOnWriteArrayList<>(); + for (File file : _itemFiles) + { + jobs.add(ThreadPool.schedule(() -> + { + final DocumentItem document = new DocumentItem(file); + document.parse(); + list.addAll(document.getItemList()); + }, 0)); + } + while (!jobs.isEmpty()) + { + for (ScheduledFuture job : jobs) + { + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } + } + } + } + else + { + for (File file : _itemFiles) { final DocumentItem document = new DocumentItem(file); document.parse(); list.addAll(document.getItemList()); - }, 0)); - } - while (!jobs.isEmpty()) - { - for (ScheduledFuture job : jobs) - { - if ((job == null) || job.isDone() || job.isCancelled()) - { - jobs.remove(job); - } } } + return list; } diff --git a/L2J_Mobius_3.0_Helios/dist/game/config/Server.ini b/L2J_Mobius_3.0_Helios/dist/game/config/Server.ini index ab3f2027cd..9409882359 100644 --- a/L2J_Mobius_3.0_Helios/dist/game/config/Server.ini +++ b/L2J_Mobius_3.0_Helios/dist/game/config/Server.ini @@ -145,6 +145,10 @@ ThreadsPerInstantThreadPool = 2 # Default: 2 UrgentPacketThreadCoreSize = 2 +# Use threads to decrease startup time. +# Default: False +ThreadsForLoading = False + # --------------------------------------------------------------------------- # Dead Lock Detector (separate thread for detecting deadlocks) diff --git a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/Config.java b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/Config.java index 4c846c4376..242c10ad48 100644 --- a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/Config.java +++ b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/Config.java @@ -436,6 +436,7 @@ public final class Config public static int INSTANT_THREAD_POOL_COUNT; public static int THREADS_PER_INSTANT_THREAD_POOL; public static int IO_PACKET_THREAD_CORE_SIZE; + public static boolean THREADS_FOR_LOADING; public static boolean DEADLOCK_DETECTOR; public static int DEADLOCK_CHECK_INTERVAL; public static boolean RESTART_ON_DEADLOCK; @@ -1299,6 +1300,7 @@ public final class Config } THREADS_PER_INSTANT_THREAD_POOL = serverSettings.getInt("ThreadsPerInstantThreadPool", 2); IO_PACKET_THREAD_CORE_SIZE = serverSettings.getInt("UrgentPacketThreadCoreSize", 2); + THREADS_FOR_LOADING = serverSettings.getBoolean("ThreadsForLoading", false); DEADLOCK_DETECTOR = serverSettings.getBoolean("DeadLockDetector", true); DEADLOCK_CHECK_INTERVAL = serverSettings.getInt("DeadLockCheckInterval", 20); diff --git a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/commons/util/IXmlReader.java b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/commons/util/IXmlReader.java index 4bfed2396e..54bb8b3292 100644 --- a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/commons/util/IXmlReader.java +++ b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/commons/util/IXmlReader.java @@ -165,29 +165,47 @@ public interface IXmlReader return false; } - final List> jobs = new CopyOnWriteArrayList<>(); - final File[] listOfFiles = dir.listFiles(); - for (File f : listOfFiles) + if (Config.THREADS_FOR_LOADING) { - if (recursive && f.isDirectory()) + final List> jobs = new CopyOnWriteArrayList<>(); + final File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { - parseDirectory(f, recursive); - } - else if (getCurrentFileFilter().accept(f)) - { - jobs.add(ThreadPool.schedule(() -> + if (recursive && file.isDirectory()) { - parseFile(f); - }, 0)); + parseDirectory(file, recursive); + } + else if (getCurrentFileFilter().accept(file)) + { + jobs.add(ThreadPool.schedule(() -> + { + parseFile(file); + }, 0)); + } + } + while (!jobs.isEmpty()) + { + for (ScheduledFuture job : jobs) + { + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } + } } } - while (!jobs.isEmpty()) + else { - for (ScheduledFuture job : jobs) + final File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { - if ((job == null) || job.isDone() || job.isCancelled()) + if (recursive && file.isDirectory()) { - jobs.remove(job); + parseDirectory(file, recursive); + } + else if (getCurrentFileFilter().accept(file)) + { + parseFile(file); } } } diff --git a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java index 806d00902a..10ae6bca06 100644 --- a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java +++ b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java @@ -95,28 +95,44 @@ public class SpawnsData implements IXmlReader } LOGGER.info(getClass().getSimpleName() + ": Initializing spawns..."); - final List> jobs = new CopyOnWriteArrayList<>(); - for (SpawnTemplate template : _spawns) + + if (Config.THREADS_FOR_LOADING) { - if (template.isSpawningByDefault()) + final List> jobs = new CopyOnWriteArrayList<>(); + for (SpawnTemplate template : _spawns) { - jobs.add(ThreadPool.schedule(() -> + if (template.isSpawningByDefault()) { - template.spawnAll(null); - template.notifyActivate(); - }, 0)); + jobs.add(ThreadPool.schedule(() -> + { + template.spawnAll(null); + template.notifyActivate(); + }, 0)); + } } - } - while (!jobs.isEmpty()) - { - for (ScheduledFuture job : jobs) + while (!jobs.isEmpty()) { - if ((job == null) || job.isDone() || job.isCancelled()) + for (ScheduledFuture job : jobs) { - jobs.remove(job); + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } } } } + else + { + for (SpawnTemplate template : _spawns) + { + if (template.isSpawningByDefault()) + { + template.spawnAll(null); + template.notifyActivate(); + } + } + } + LOGGER.info(getClass().getSimpleName() + ": All spawns has been initialized!"); } diff --git a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/engines/DocumentEngine.java b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/engines/DocumentEngine.java index 10f04f4fb3..68302f92da 100644 --- a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/engines/DocumentEngine.java +++ b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/engines/DocumentEngine.java @@ -69,26 +69,40 @@ public class DocumentEngine public List loadItems() { final List list = new CopyOnWriteArrayList<>(); - final List> jobs = new CopyOnWriteArrayList<>(); - for (File file : _itemFiles) + + if (Config.THREADS_FOR_LOADING) { - jobs.add(ThreadPool.schedule(() -> + final List> jobs = new CopyOnWriteArrayList<>(); + for (File file : _itemFiles) + { + jobs.add(ThreadPool.schedule(() -> + { + final DocumentItem document = new DocumentItem(file); + document.parse(); + list.addAll(document.getItemList()); + }, 0)); + } + while (!jobs.isEmpty()) + { + for (ScheduledFuture job : jobs) + { + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } + } + } + } + else + { + for (File file : _itemFiles) { final DocumentItem document = new DocumentItem(file); document.parse(); list.addAll(document.getItemList()); - }, 0)); - } - while (!jobs.isEmpty()) - { - for (ScheduledFuture job : jobs) - { - if ((job == null) || job.isDone() || job.isCancelled()) - { - jobs.remove(job); - } } } + return list; } diff --git a/L2J_Mobius_4.0_GrandCrusade/dist/game/config/Server.ini b/L2J_Mobius_4.0_GrandCrusade/dist/game/config/Server.ini index fcdb15085f..7860697805 100644 --- a/L2J_Mobius_4.0_GrandCrusade/dist/game/config/Server.ini +++ b/L2J_Mobius_4.0_GrandCrusade/dist/game/config/Server.ini @@ -145,6 +145,10 @@ ThreadsPerInstantThreadPool = 2 # Default: 2 UrgentPacketThreadCoreSize = 2 +# Use threads to decrease startup time. +# Default: False +ThreadsForLoading = False + # --------------------------------------------------------------------------- # Dead Lock Detector (separate thread for detecting deadlocks) diff --git a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/Config.java b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/Config.java index 93eb9751db..6670015016 100644 --- a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/Config.java +++ b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/Config.java @@ -430,6 +430,7 @@ public final class Config public static int INSTANT_THREAD_POOL_COUNT; public static int THREADS_PER_INSTANT_THREAD_POOL; public static int IO_PACKET_THREAD_CORE_SIZE; + public static boolean THREADS_FOR_LOADING; public static boolean DEADLOCK_DETECTOR; public static int DEADLOCK_CHECK_INTERVAL; public static boolean RESTART_ON_DEADLOCK; @@ -1292,6 +1293,7 @@ public final class Config } THREADS_PER_INSTANT_THREAD_POOL = serverSettings.getInt("ThreadsPerInstantThreadPool", 2); IO_PACKET_THREAD_CORE_SIZE = serverSettings.getInt("UrgentPacketThreadCoreSize", 2); + THREADS_FOR_LOADING = serverSettings.getBoolean("ThreadsForLoading", false); DEADLOCK_DETECTOR = serverSettings.getBoolean("DeadLockDetector", true); DEADLOCK_CHECK_INTERVAL = serverSettings.getInt("DeadLockCheckInterval", 20); diff --git a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/commons/util/IXmlReader.java b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/commons/util/IXmlReader.java index 4bfed2396e..54bb8b3292 100644 --- a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/commons/util/IXmlReader.java +++ b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/commons/util/IXmlReader.java @@ -165,29 +165,47 @@ public interface IXmlReader return false; } - final List> jobs = new CopyOnWriteArrayList<>(); - final File[] listOfFiles = dir.listFiles(); - for (File f : listOfFiles) + if (Config.THREADS_FOR_LOADING) { - if (recursive && f.isDirectory()) + final List> jobs = new CopyOnWriteArrayList<>(); + final File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { - parseDirectory(f, recursive); - } - else if (getCurrentFileFilter().accept(f)) - { - jobs.add(ThreadPool.schedule(() -> + if (recursive && file.isDirectory()) { - parseFile(f); - }, 0)); + parseDirectory(file, recursive); + } + else if (getCurrentFileFilter().accept(file)) + { + jobs.add(ThreadPool.schedule(() -> + { + parseFile(file); + }, 0)); + } + } + while (!jobs.isEmpty()) + { + for (ScheduledFuture job : jobs) + { + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } + } } } - while (!jobs.isEmpty()) + else { - for (ScheduledFuture job : jobs) + final File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { - if ((job == null) || job.isDone() || job.isCancelled()) + if (recursive && file.isDirectory()) { - jobs.remove(job); + parseDirectory(file, recursive); + } + else if (getCurrentFileFilter().accept(file)) + { + parseFile(file); } } } diff --git a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java index 806d00902a..10ae6bca06 100644 --- a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java +++ b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java @@ -95,28 +95,44 @@ public class SpawnsData implements IXmlReader } LOGGER.info(getClass().getSimpleName() + ": Initializing spawns..."); - final List> jobs = new CopyOnWriteArrayList<>(); - for (SpawnTemplate template : _spawns) + + if (Config.THREADS_FOR_LOADING) { - if (template.isSpawningByDefault()) + final List> jobs = new CopyOnWriteArrayList<>(); + for (SpawnTemplate template : _spawns) { - jobs.add(ThreadPool.schedule(() -> + if (template.isSpawningByDefault()) { - template.spawnAll(null); - template.notifyActivate(); - }, 0)); + jobs.add(ThreadPool.schedule(() -> + { + template.spawnAll(null); + template.notifyActivate(); + }, 0)); + } } - } - while (!jobs.isEmpty()) - { - for (ScheduledFuture job : jobs) + while (!jobs.isEmpty()) { - if ((job == null) || job.isDone() || job.isCancelled()) + for (ScheduledFuture job : jobs) { - jobs.remove(job); + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } } } } + else + { + for (SpawnTemplate template : _spawns) + { + if (template.isSpawningByDefault()) + { + template.spawnAll(null); + template.notifyActivate(); + } + } + } + LOGGER.info(getClass().getSimpleName() + ": All spawns has been initialized!"); } diff --git a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/engines/DocumentEngine.java b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/engines/DocumentEngine.java index 10f04f4fb3..68302f92da 100644 --- a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/engines/DocumentEngine.java +++ b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/engines/DocumentEngine.java @@ -69,26 +69,40 @@ public class DocumentEngine public List loadItems() { final List list = new CopyOnWriteArrayList<>(); - final List> jobs = new CopyOnWriteArrayList<>(); - for (File file : _itemFiles) + + if (Config.THREADS_FOR_LOADING) { - jobs.add(ThreadPool.schedule(() -> + final List> jobs = new CopyOnWriteArrayList<>(); + for (File file : _itemFiles) + { + jobs.add(ThreadPool.schedule(() -> + { + final DocumentItem document = new DocumentItem(file); + document.parse(); + list.addAll(document.getItemList()); + }, 0)); + } + while (!jobs.isEmpty()) + { + for (ScheduledFuture job : jobs) + { + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } + } + } + } + else + { + for (File file : _itemFiles) { final DocumentItem document = new DocumentItem(file); document.parse(); list.addAll(document.getItemList()); - }, 0)); - } - while (!jobs.isEmpty()) - { - for (ScheduledFuture job : jobs) - { - if ((job == null) || job.isDone() || job.isCancelled()) - { - jobs.remove(job); - } } } + return list; } diff --git a/L2J_Mobius_5.0_Salvation/dist/game/config/Server.ini b/L2J_Mobius_5.0_Salvation/dist/game/config/Server.ini index 9b87931948..55c484028b 100644 --- a/L2J_Mobius_5.0_Salvation/dist/game/config/Server.ini +++ b/L2J_Mobius_5.0_Salvation/dist/game/config/Server.ini @@ -145,6 +145,10 @@ ThreadsPerInstantThreadPool = 2 # Default: 2 UrgentPacketThreadCoreSize = 2 +# Use threads to decrease startup time. +# Default: False +ThreadsForLoading = False + # --------------------------------------------------------------------------- # Dead Lock Detector (separate thread for detecting deadlocks) diff --git a/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/Config.java b/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/Config.java index 053bf6cfba..968fc826f8 100644 --- a/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/Config.java +++ b/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/Config.java @@ -425,6 +425,7 @@ public final class Config public static int INSTANT_THREAD_POOL_COUNT; public static int THREADS_PER_INSTANT_THREAD_POOL; public static int IO_PACKET_THREAD_CORE_SIZE; + public static boolean THREADS_FOR_LOADING; public static boolean DEADLOCK_DETECTOR; public static int DEADLOCK_CHECK_INTERVAL; public static boolean RESTART_ON_DEADLOCK; @@ -1287,6 +1288,7 @@ public final class Config } THREADS_PER_INSTANT_THREAD_POOL = serverSettings.getInt("ThreadsPerInstantThreadPool", 2); IO_PACKET_THREAD_CORE_SIZE = serverSettings.getInt("UrgentPacketThreadCoreSize", 2); + THREADS_FOR_LOADING = serverSettings.getBoolean("ThreadsForLoading", false); DEADLOCK_DETECTOR = serverSettings.getBoolean("DeadLockDetector", true); DEADLOCK_CHECK_INTERVAL = serverSettings.getInt("DeadLockCheckInterval", 20); diff --git a/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/commons/util/IXmlReader.java b/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/commons/util/IXmlReader.java index 4bfed2396e..54bb8b3292 100644 --- a/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/commons/util/IXmlReader.java +++ b/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/commons/util/IXmlReader.java @@ -165,29 +165,47 @@ public interface IXmlReader return false; } - final List> jobs = new CopyOnWriteArrayList<>(); - final File[] listOfFiles = dir.listFiles(); - for (File f : listOfFiles) + if (Config.THREADS_FOR_LOADING) { - if (recursive && f.isDirectory()) + final List> jobs = new CopyOnWriteArrayList<>(); + final File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { - parseDirectory(f, recursive); - } - else if (getCurrentFileFilter().accept(f)) - { - jobs.add(ThreadPool.schedule(() -> + if (recursive && file.isDirectory()) { - parseFile(f); - }, 0)); + parseDirectory(file, recursive); + } + else if (getCurrentFileFilter().accept(file)) + { + jobs.add(ThreadPool.schedule(() -> + { + parseFile(file); + }, 0)); + } + } + while (!jobs.isEmpty()) + { + for (ScheduledFuture job : jobs) + { + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } + } } } - while (!jobs.isEmpty()) + else { - for (ScheduledFuture job : jobs) + final File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { - if ((job == null) || job.isDone() || job.isCancelled()) + if (recursive && file.isDirectory()) { - jobs.remove(job); + parseDirectory(file, recursive); + } + else if (getCurrentFileFilter().accept(file)) + { + parseFile(file); } } } diff --git a/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java b/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java index 806d00902a..10ae6bca06 100644 --- a/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java +++ b/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java @@ -95,28 +95,44 @@ public class SpawnsData implements IXmlReader } LOGGER.info(getClass().getSimpleName() + ": Initializing spawns..."); - final List> jobs = new CopyOnWriteArrayList<>(); - for (SpawnTemplate template : _spawns) + + if (Config.THREADS_FOR_LOADING) { - if (template.isSpawningByDefault()) + final List> jobs = new CopyOnWriteArrayList<>(); + for (SpawnTemplate template : _spawns) { - jobs.add(ThreadPool.schedule(() -> + if (template.isSpawningByDefault()) { - template.spawnAll(null); - template.notifyActivate(); - }, 0)); + jobs.add(ThreadPool.schedule(() -> + { + template.spawnAll(null); + template.notifyActivate(); + }, 0)); + } } - } - while (!jobs.isEmpty()) - { - for (ScheduledFuture job : jobs) + while (!jobs.isEmpty()) { - if ((job == null) || job.isDone() || job.isCancelled()) + for (ScheduledFuture job : jobs) { - jobs.remove(job); + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } } } } + else + { + for (SpawnTemplate template : _spawns) + { + if (template.isSpawningByDefault()) + { + template.spawnAll(null); + template.notifyActivate(); + } + } + } + LOGGER.info(getClass().getSimpleName() + ": All spawns has been initialized!"); } diff --git a/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/gameserver/engines/DocumentEngine.java b/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/gameserver/engines/DocumentEngine.java index 10f04f4fb3..68302f92da 100644 --- a/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/gameserver/engines/DocumentEngine.java +++ b/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/gameserver/engines/DocumentEngine.java @@ -69,26 +69,40 @@ public class DocumentEngine public List loadItems() { final List list = new CopyOnWriteArrayList<>(); - final List> jobs = new CopyOnWriteArrayList<>(); - for (File file : _itemFiles) + + if (Config.THREADS_FOR_LOADING) { - jobs.add(ThreadPool.schedule(() -> + final List> jobs = new CopyOnWriteArrayList<>(); + for (File file : _itemFiles) + { + jobs.add(ThreadPool.schedule(() -> + { + final DocumentItem document = new DocumentItem(file); + document.parse(); + list.addAll(document.getItemList()); + }, 0)); + } + while (!jobs.isEmpty()) + { + for (ScheduledFuture job : jobs) + { + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } + } + } + } + else + { + for (File file : _itemFiles) { final DocumentItem document = new DocumentItem(file); document.parse(); list.addAll(document.getItemList()); - }, 0)); - } - while (!jobs.isEmpty()) - { - for (ScheduledFuture job : jobs) - { - if ((job == null) || job.isDone() || job.isCancelled()) - { - jobs.remove(job); - } } } + return list; } diff --git a/L2J_Mobius_5.5_EtinasFate/dist/game/config/Server.ini b/L2J_Mobius_5.5_EtinasFate/dist/game/config/Server.ini index 0ec56a4ff3..54116691c7 100644 --- a/L2J_Mobius_5.5_EtinasFate/dist/game/config/Server.ini +++ b/L2J_Mobius_5.5_EtinasFate/dist/game/config/Server.ini @@ -145,6 +145,10 @@ ThreadsPerInstantThreadPool = 2 # Default: 2 UrgentPacketThreadCoreSize = 2 +# Use threads to decrease startup time. +# Default: False +ThreadsForLoading = False + # --------------------------------------------------------------------------- # Dead Lock Detector (separate thread for detecting deadlocks) diff --git a/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/Config.java b/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/Config.java index 053bf6cfba..968fc826f8 100644 --- a/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/Config.java +++ b/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/Config.java @@ -425,6 +425,7 @@ public final class Config public static int INSTANT_THREAD_POOL_COUNT; public static int THREADS_PER_INSTANT_THREAD_POOL; public static int IO_PACKET_THREAD_CORE_SIZE; + public static boolean THREADS_FOR_LOADING; public static boolean DEADLOCK_DETECTOR; public static int DEADLOCK_CHECK_INTERVAL; public static boolean RESTART_ON_DEADLOCK; @@ -1287,6 +1288,7 @@ public final class Config } THREADS_PER_INSTANT_THREAD_POOL = serverSettings.getInt("ThreadsPerInstantThreadPool", 2); IO_PACKET_THREAD_CORE_SIZE = serverSettings.getInt("UrgentPacketThreadCoreSize", 2); + THREADS_FOR_LOADING = serverSettings.getBoolean("ThreadsForLoading", false); DEADLOCK_DETECTOR = serverSettings.getBoolean("DeadLockDetector", true); DEADLOCK_CHECK_INTERVAL = serverSettings.getInt("DeadLockCheckInterval", 20); diff --git a/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/commons/util/IXmlReader.java b/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/commons/util/IXmlReader.java index 4bfed2396e..54bb8b3292 100644 --- a/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/commons/util/IXmlReader.java +++ b/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/commons/util/IXmlReader.java @@ -165,29 +165,47 @@ public interface IXmlReader return false; } - final List> jobs = new CopyOnWriteArrayList<>(); - final File[] listOfFiles = dir.listFiles(); - for (File f : listOfFiles) + if (Config.THREADS_FOR_LOADING) { - if (recursive && f.isDirectory()) + final List> jobs = new CopyOnWriteArrayList<>(); + final File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { - parseDirectory(f, recursive); - } - else if (getCurrentFileFilter().accept(f)) - { - jobs.add(ThreadPool.schedule(() -> + if (recursive && file.isDirectory()) { - parseFile(f); - }, 0)); + parseDirectory(file, recursive); + } + else if (getCurrentFileFilter().accept(file)) + { + jobs.add(ThreadPool.schedule(() -> + { + parseFile(file); + }, 0)); + } + } + while (!jobs.isEmpty()) + { + for (ScheduledFuture job : jobs) + { + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } + } } } - while (!jobs.isEmpty()) + else { - for (ScheduledFuture job : jobs) + final File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { - if ((job == null) || job.isDone() || job.isCancelled()) + if (recursive && file.isDirectory()) { - jobs.remove(job); + parseDirectory(file, recursive); + } + else if (getCurrentFileFilter().accept(file)) + { + parseFile(file); } } } diff --git a/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java b/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java index 806d00902a..10ae6bca06 100644 --- a/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java +++ b/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java @@ -95,28 +95,44 @@ public class SpawnsData implements IXmlReader } LOGGER.info(getClass().getSimpleName() + ": Initializing spawns..."); - final List> jobs = new CopyOnWriteArrayList<>(); - for (SpawnTemplate template : _spawns) + + if (Config.THREADS_FOR_LOADING) { - if (template.isSpawningByDefault()) + final List> jobs = new CopyOnWriteArrayList<>(); + for (SpawnTemplate template : _spawns) { - jobs.add(ThreadPool.schedule(() -> + if (template.isSpawningByDefault()) { - template.spawnAll(null); - template.notifyActivate(); - }, 0)); + jobs.add(ThreadPool.schedule(() -> + { + template.spawnAll(null); + template.notifyActivate(); + }, 0)); + } } - } - while (!jobs.isEmpty()) - { - for (ScheduledFuture job : jobs) + while (!jobs.isEmpty()) { - if ((job == null) || job.isDone() || job.isCancelled()) + for (ScheduledFuture job : jobs) { - jobs.remove(job); + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } } } } + else + { + for (SpawnTemplate template : _spawns) + { + if (template.isSpawningByDefault()) + { + template.spawnAll(null); + template.notifyActivate(); + } + } + } + LOGGER.info(getClass().getSimpleName() + ": All spawns has been initialized!"); } diff --git a/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/gameserver/engines/DocumentEngine.java b/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/gameserver/engines/DocumentEngine.java index 10f04f4fb3..68302f92da 100644 --- a/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/gameserver/engines/DocumentEngine.java +++ b/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/gameserver/engines/DocumentEngine.java @@ -69,26 +69,40 @@ public class DocumentEngine public List loadItems() { final List list = new CopyOnWriteArrayList<>(); - final List> jobs = new CopyOnWriteArrayList<>(); - for (File file : _itemFiles) + + if (Config.THREADS_FOR_LOADING) { - jobs.add(ThreadPool.schedule(() -> + final List> jobs = new CopyOnWriteArrayList<>(); + for (File file : _itemFiles) + { + jobs.add(ThreadPool.schedule(() -> + { + final DocumentItem document = new DocumentItem(file); + document.parse(); + list.addAll(document.getItemList()); + }, 0)); + } + while (!jobs.isEmpty()) + { + for (ScheduledFuture job : jobs) + { + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } + } + } + } + else + { + for (File file : _itemFiles) { final DocumentItem document = new DocumentItem(file); document.parse(); list.addAll(document.getItemList()); - }, 0)); - } - while (!jobs.isEmpty()) - { - for (ScheduledFuture job : jobs) - { - if ((job == null) || job.isDone() || job.isCancelled()) - { - jobs.remove(job); - } } } + return list; } diff --git a/L2J_Mobius_6.0_Fafurion/dist/game/config/Server.ini b/L2J_Mobius_6.0_Fafurion/dist/game/config/Server.ini index 568fce79d9..9262302184 100644 --- a/L2J_Mobius_6.0_Fafurion/dist/game/config/Server.ini +++ b/L2J_Mobius_6.0_Fafurion/dist/game/config/Server.ini @@ -145,6 +145,10 @@ ThreadsPerInstantThreadPool = 2 # Default: 2 UrgentPacketThreadCoreSize = 2 +# Use threads to decrease startup time. +# Default: False +ThreadsForLoading = False + # --------------------------------------------------------------------------- # Dead Lock Detector (separate thread for detecting deadlocks) diff --git a/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/Config.java b/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/Config.java index 97446a9a9f..f230726d7a 100644 --- a/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/Config.java +++ b/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/Config.java @@ -426,6 +426,7 @@ public final class Config public static int INSTANT_THREAD_POOL_COUNT; public static int THREADS_PER_INSTANT_THREAD_POOL; public static int IO_PACKET_THREAD_CORE_SIZE; + public static boolean THREADS_FOR_LOADING; public static boolean DEADLOCK_DETECTOR; public static int DEADLOCK_CHECK_INTERVAL; public static boolean RESTART_ON_DEADLOCK; @@ -1294,6 +1295,7 @@ public final class Config } THREADS_PER_INSTANT_THREAD_POOL = serverSettings.getInt("ThreadsPerInstantThreadPool", 2); IO_PACKET_THREAD_CORE_SIZE = serverSettings.getInt("UrgentPacketThreadCoreSize", 2); + THREADS_FOR_LOADING = serverSettings.getBoolean("ThreadsForLoading", false); DEADLOCK_DETECTOR = serverSettings.getBoolean("DeadLockDetector", true); DEADLOCK_CHECK_INTERVAL = serverSettings.getInt("DeadLockCheckInterval", 20); diff --git a/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/commons/util/IXmlReader.java b/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/commons/util/IXmlReader.java index 4bfed2396e..54bb8b3292 100644 --- a/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/commons/util/IXmlReader.java +++ b/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/commons/util/IXmlReader.java @@ -165,29 +165,47 @@ public interface IXmlReader return false; } - final List> jobs = new CopyOnWriteArrayList<>(); - final File[] listOfFiles = dir.listFiles(); - for (File f : listOfFiles) + if (Config.THREADS_FOR_LOADING) { - if (recursive && f.isDirectory()) + final List> jobs = new CopyOnWriteArrayList<>(); + final File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { - parseDirectory(f, recursive); - } - else if (getCurrentFileFilter().accept(f)) - { - jobs.add(ThreadPool.schedule(() -> + if (recursive && file.isDirectory()) { - parseFile(f); - }, 0)); + parseDirectory(file, recursive); + } + else if (getCurrentFileFilter().accept(file)) + { + jobs.add(ThreadPool.schedule(() -> + { + parseFile(file); + }, 0)); + } + } + while (!jobs.isEmpty()) + { + for (ScheduledFuture job : jobs) + { + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } + } } } - while (!jobs.isEmpty()) + else { - for (ScheduledFuture job : jobs) + final File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { - if ((job == null) || job.isDone() || job.isCancelled()) + if (recursive && file.isDirectory()) { - jobs.remove(job); + parseDirectory(file, recursive); + } + else if (getCurrentFileFilter().accept(file)) + { + parseFile(file); } } } diff --git a/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java b/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java index 806d00902a..10ae6bca06 100644 --- a/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java +++ b/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java @@ -95,28 +95,44 @@ public class SpawnsData implements IXmlReader } LOGGER.info(getClass().getSimpleName() + ": Initializing spawns..."); - final List> jobs = new CopyOnWriteArrayList<>(); - for (SpawnTemplate template : _spawns) + + if (Config.THREADS_FOR_LOADING) { - if (template.isSpawningByDefault()) + final List> jobs = new CopyOnWriteArrayList<>(); + for (SpawnTemplate template : _spawns) { - jobs.add(ThreadPool.schedule(() -> + if (template.isSpawningByDefault()) { - template.spawnAll(null); - template.notifyActivate(); - }, 0)); + jobs.add(ThreadPool.schedule(() -> + { + template.spawnAll(null); + template.notifyActivate(); + }, 0)); + } } - } - while (!jobs.isEmpty()) - { - for (ScheduledFuture job : jobs) + while (!jobs.isEmpty()) { - if ((job == null) || job.isDone() || job.isCancelled()) + for (ScheduledFuture job : jobs) { - jobs.remove(job); + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } } } } + else + { + for (SpawnTemplate template : _spawns) + { + if (template.isSpawningByDefault()) + { + template.spawnAll(null); + template.notifyActivate(); + } + } + } + LOGGER.info(getClass().getSimpleName() + ": All spawns has been initialized!"); } diff --git a/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/gameserver/engines/DocumentEngine.java b/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/gameserver/engines/DocumentEngine.java index 10f04f4fb3..68302f92da 100644 --- a/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/gameserver/engines/DocumentEngine.java +++ b/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/gameserver/engines/DocumentEngine.java @@ -69,26 +69,40 @@ public class DocumentEngine public List loadItems() { final List list = new CopyOnWriteArrayList<>(); - final List> jobs = new CopyOnWriteArrayList<>(); - for (File file : _itemFiles) + + if (Config.THREADS_FOR_LOADING) { - jobs.add(ThreadPool.schedule(() -> + final List> jobs = new CopyOnWriteArrayList<>(); + for (File file : _itemFiles) + { + jobs.add(ThreadPool.schedule(() -> + { + final DocumentItem document = new DocumentItem(file); + document.parse(); + list.addAll(document.getItemList()); + }, 0)); + } + while (!jobs.isEmpty()) + { + for (ScheduledFuture job : jobs) + { + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } + } + } + } + else + { + for (File file : _itemFiles) { final DocumentItem document = new DocumentItem(file); document.parse(); list.addAll(document.getItemList()); - }, 0)); - } - while (!jobs.isEmpty()) - { - for (ScheduledFuture job : jobs) - { - if ((job == null) || job.isDone() || job.isCancelled()) - { - jobs.remove(job); - } } } + return list; } diff --git a/L2J_Mobius_CT_2.6_HighFive/dist/game/config/Server.ini b/L2J_Mobius_CT_2.6_HighFive/dist/game/config/Server.ini index ad619c5b5b..b33d9e8a8f 100644 --- a/L2J_Mobius_CT_2.6_HighFive/dist/game/config/Server.ini +++ b/L2J_Mobius_CT_2.6_HighFive/dist/game/config/Server.ini @@ -145,6 +145,10 @@ ThreadsPerInstantThreadPool = 2 # Default: 2 UrgentPacketThreadCoreSize = 2 +# Use threads to decrease startup time. +# Default: False +ThreadsForLoading = False + # --------------------------------------------------------------------------- # Dead Lock Detector (separate thread for detecting deadlocks) diff --git a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/Config.java b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/Config.java index 0b6cecef18..ccf0a6efb5 100644 --- a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/Config.java +++ b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/Config.java @@ -503,6 +503,7 @@ public final class Config public static int INSTANT_THREAD_POOL_COUNT; public static int THREADS_PER_INSTANT_THREAD_POOL; public static int IO_PACKET_THREAD_CORE_SIZE; + public static boolean THREADS_FOR_LOADING; public static boolean DEADLOCK_DETECTOR; public static int DEADLOCK_CHECK_INTERVAL; public static boolean RESTART_ON_DEADLOCK; @@ -1453,6 +1454,7 @@ public final class Config } THREADS_PER_INSTANT_THREAD_POOL = serverSettings.getInt("ThreadsPerInstantThreadPool", 2); IO_PACKET_THREAD_CORE_SIZE = serverSettings.getInt("UrgentPacketThreadCoreSize", 2); + THREADS_FOR_LOADING = serverSettings.getBoolean("ThreadsForLoading", false); DEADLOCK_DETECTOR = serverSettings.getBoolean("DeadLockDetector", true); DEADLOCK_CHECK_INTERVAL = serverSettings.getInt("DeadLockCheckInterval", 20); diff --git a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/commons/util/IXmlReader.java b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/commons/util/IXmlReader.java index 4bfed2396e..54bb8b3292 100644 --- a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/commons/util/IXmlReader.java +++ b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/commons/util/IXmlReader.java @@ -165,29 +165,47 @@ public interface IXmlReader return false; } - final List> jobs = new CopyOnWriteArrayList<>(); - final File[] listOfFiles = dir.listFiles(); - for (File f : listOfFiles) + if (Config.THREADS_FOR_LOADING) { - if (recursive && f.isDirectory()) + final List> jobs = new CopyOnWriteArrayList<>(); + final File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { - parseDirectory(f, recursive); - } - else if (getCurrentFileFilter().accept(f)) - { - jobs.add(ThreadPool.schedule(() -> + if (recursive && file.isDirectory()) { - parseFile(f); - }, 0)); + parseDirectory(file, recursive); + } + else if (getCurrentFileFilter().accept(file)) + { + jobs.add(ThreadPool.schedule(() -> + { + parseFile(file); + }, 0)); + } + } + while (!jobs.isEmpty()) + { + for (ScheduledFuture job : jobs) + { + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } + } } } - while (!jobs.isEmpty()) + else { - for (ScheduledFuture job : jobs) + final File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { - if ((job == null) || job.isDone() || job.isCancelled()) + if (recursive && file.isDirectory()) { - jobs.remove(job); + parseDirectory(file, recursive); + } + else if (getCurrentFileFilter().accept(file)) + { + parseFile(file); } } } diff --git a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/engines/DocumentEngine.java b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/engines/DocumentEngine.java index 026aa43597..047ffb331d 100644 --- a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/engines/DocumentEngine.java +++ b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/engines/DocumentEngine.java @@ -87,10 +87,39 @@ public class DocumentEngine public void loadAllSkills(Map allSkills) { - final List> jobs = new CopyOnWriteArrayList<>(); - for (File file : _skillFiles) + if (Config.THREADS_FOR_LOADING) { - jobs.add(ThreadPool.schedule(() -> + final List> jobs = new CopyOnWriteArrayList<>(); + for (File file : _skillFiles) + { + jobs.add(ThreadPool.schedule(() -> + { + final List skills = loadSkills(file); + if (skills == null) + { + return; + } + for (Skill skill : skills) + { + allSkills.put(SkillData.getSkillHashCode(skill), skill); + count++; + } + }, 0)); + } + while (!jobs.isEmpty()) + { + for (ScheduledFuture job : jobs) + { + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } + } + } + } + else + { + for (File file : _skillFiles) { final List skills = loadSkills(file); if (skills == null) @@ -102,18 +131,9 @@ public class DocumentEngine allSkills.put(SkillData.getSkillHashCode(skill), skill); count++; } - }, 0)); - } - while (!jobs.isEmpty()) - { - for (ScheduledFuture job : jobs) - { - if ((job == null) || job.isDone() || job.isCancelled()) - { - jobs.remove(job); - } } } + LOGGER.info(getClass().getSimpleName() + ": Loaded " + count + " Skill templates from XML files."); } @@ -123,27 +143,41 @@ public class DocumentEngine */ public List loadItems() { - final List> jobs = new CopyOnWriteArrayList<>(); final List list = new CopyOnWriteArrayList<>(); - for (File file : _itemFiles) + + if (Config.THREADS_FOR_LOADING) { - jobs.add(ThreadPool.schedule(() -> + final List> jobs = new CopyOnWriteArrayList<>(); + for (File file : _itemFiles) + { + jobs.add(ThreadPool.schedule(() -> + { + final DocumentItem document = new DocumentItem(file); + document.parse(); + list.addAll(document.getItemList()); + }, 0)); + } + while (!jobs.isEmpty()) + { + for (ScheduledFuture job : jobs) + { + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } + } + } + } + else + { + for (File file : _itemFiles) { final DocumentItem document = new DocumentItem(file); document.parse(); list.addAll(document.getItemList()); - }, 0)); - } - while (!jobs.isEmpty()) - { - for (ScheduledFuture job : jobs) - { - if ((job == null) || job.isDone() || job.isCancelled()) - { - jobs.remove(job); - } } } + return list; } diff --git a/L2J_Mobius_Classic_2.0_Saviors/dist/game/config/Server.ini b/L2J_Mobius_Classic_2.0_Saviors/dist/game/config/Server.ini index 5a181b4188..22449647f1 100644 --- a/L2J_Mobius_Classic_2.0_Saviors/dist/game/config/Server.ini +++ b/L2J_Mobius_Classic_2.0_Saviors/dist/game/config/Server.ini @@ -145,6 +145,10 @@ ThreadsPerInstantThreadPool = 2 # Default: 2 UrgentPacketThreadCoreSize = 2 +# Use threads to decrease startup time. +# Default: False +ThreadsForLoading = False + # --------------------------------------------------------------------------- # Dead Lock Detector (separate thread for detecting deadlocks) diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/Config.java b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/Config.java index 9aa164a69d..fdbf84a660 100644 --- a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/Config.java +++ b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/Config.java @@ -436,6 +436,7 @@ public final class Config public static int INSTANT_THREAD_POOL_COUNT; public static int THREADS_PER_INSTANT_THREAD_POOL; public static int IO_PACKET_THREAD_CORE_SIZE; + public static boolean THREADS_FOR_LOADING; public static boolean DEADLOCK_DETECTOR; public static int DEADLOCK_CHECK_INTERVAL; public static boolean RESTART_ON_DEADLOCK; @@ -1231,6 +1232,7 @@ public final class Config } THREADS_PER_INSTANT_THREAD_POOL = serverSettings.getInt("ThreadsPerInstantThreadPool", 2); IO_PACKET_THREAD_CORE_SIZE = serverSettings.getInt("UrgentPacketThreadCoreSize", 2); + THREADS_FOR_LOADING = serverSettings.getBoolean("ThreadsForLoading", false); DEADLOCK_DETECTOR = serverSettings.getBoolean("DeadLockDetector", true); DEADLOCK_CHECK_INTERVAL = serverSettings.getInt("DeadLockCheckInterval", 20); diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/commons/util/IXmlReader.java b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/commons/util/IXmlReader.java index 4bfed2396e..54bb8b3292 100644 --- a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/commons/util/IXmlReader.java +++ b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/commons/util/IXmlReader.java @@ -165,29 +165,47 @@ public interface IXmlReader return false; } - final List> jobs = new CopyOnWriteArrayList<>(); - final File[] listOfFiles = dir.listFiles(); - for (File f : listOfFiles) + if (Config.THREADS_FOR_LOADING) { - if (recursive && f.isDirectory()) + final List> jobs = new CopyOnWriteArrayList<>(); + final File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { - parseDirectory(f, recursive); - } - else if (getCurrentFileFilter().accept(f)) - { - jobs.add(ThreadPool.schedule(() -> + if (recursive && file.isDirectory()) { - parseFile(f); - }, 0)); + parseDirectory(file, recursive); + } + else if (getCurrentFileFilter().accept(file)) + { + jobs.add(ThreadPool.schedule(() -> + { + parseFile(file); + }, 0)); + } + } + while (!jobs.isEmpty()) + { + for (ScheduledFuture job : jobs) + { + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } + } } } - while (!jobs.isEmpty()) + else { - for (ScheduledFuture job : jobs) + final File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { - if ((job == null) || job.isDone() || job.isCancelled()) + if (recursive && file.isDirectory()) { - jobs.remove(job); + parseDirectory(file, recursive); + } + else if (getCurrentFileFilter().accept(file)) + { + parseFile(file); } } } diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java index 806d00902a..10ae6bca06 100644 --- a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java +++ b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java @@ -95,28 +95,44 @@ public class SpawnsData implements IXmlReader } LOGGER.info(getClass().getSimpleName() + ": Initializing spawns..."); - final List> jobs = new CopyOnWriteArrayList<>(); - for (SpawnTemplate template : _spawns) + + if (Config.THREADS_FOR_LOADING) { - if (template.isSpawningByDefault()) + final List> jobs = new CopyOnWriteArrayList<>(); + for (SpawnTemplate template : _spawns) { - jobs.add(ThreadPool.schedule(() -> + if (template.isSpawningByDefault()) { - template.spawnAll(null); - template.notifyActivate(); - }, 0)); + jobs.add(ThreadPool.schedule(() -> + { + template.spawnAll(null); + template.notifyActivate(); + }, 0)); + } } - } - while (!jobs.isEmpty()) - { - for (ScheduledFuture job : jobs) + while (!jobs.isEmpty()) { - if ((job == null) || job.isDone() || job.isCancelled()) + for (ScheduledFuture job : jobs) { - jobs.remove(job); + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } } } } + else + { + for (SpawnTemplate template : _spawns) + { + if (template.isSpawningByDefault()) + { + template.spawnAll(null); + template.notifyActivate(); + } + } + } + LOGGER.info(getClass().getSimpleName() + ": All spawns has been initialized!"); } diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/engines/DocumentEngine.java b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/engines/DocumentEngine.java index 10f04f4fb3..68302f92da 100644 --- a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/engines/DocumentEngine.java +++ b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/engines/DocumentEngine.java @@ -69,26 +69,40 @@ public class DocumentEngine public List loadItems() { final List list = new CopyOnWriteArrayList<>(); - final List> jobs = new CopyOnWriteArrayList<>(); - for (File file : _itemFiles) + + if (Config.THREADS_FOR_LOADING) { - jobs.add(ThreadPool.schedule(() -> + final List> jobs = new CopyOnWriteArrayList<>(); + for (File file : _itemFiles) + { + jobs.add(ThreadPool.schedule(() -> + { + final DocumentItem document = new DocumentItem(file); + document.parse(); + list.addAll(document.getItemList()); + }, 0)); + } + while (!jobs.isEmpty()) + { + for (ScheduledFuture job : jobs) + { + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } + } + } + } + else + { + for (File file : _itemFiles) { final DocumentItem document = new DocumentItem(file); document.parse(); list.addAll(document.getItemList()); - }, 0)); - } - while (!jobs.isEmpty()) - { - for (ScheduledFuture job : jobs) - { - if ((job == null) || job.isDone() || job.isCancelled()) - { - jobs.remove(job); - } } } + return list; } diff --git a/L2J_Mobius_Classic_2.1_Zaken/dist/game/config/Server.ini b/L2J_Mobius_Classic_2.1_Zaken/dist/game/config/Server.ini index 196b2dd6d1..14a5f41c82 100644 --- a/L2J_Mobius_Classic_2.1_Zaken/dist/game/config/Server.ini +++ b/L2J_Mobius_Classic_2.1_Zaken/dist/game/config/Server.ini @@ -145,6 +145,10 @@ ThreadsPerInstantThreadPool = 2 # Default: 2 UrgentPacketThreadCoreSize = 2 +# Use threads to decrease startup time. +# Default: False +ThreadsForLoading = False + # --------------------------------------------------------------------------- # Dead Lock Detector (separate thread for detecting deadlocks) diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/Config.java b/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/Config.java index 4069e1357d..2b33efbf5b 100644 --- a/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/Config.java +++ b/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/Config.java @@ -436,6 +436,7 @@ public final class Config public static int INSTANT_THREAD_POOL_COUNT; public static int THREADS_PER_INSTANT_THREAD_POOL; public static int IO_PACKET_THREAD_CORE_SIZE; + public static boolean THREADS_FOR_LOADING; public static boolean DEADLOCK_DETECTOR; public static int DEADLOCK_CHECK_INTERVAL; public static boolean RESTART_ON_DEADLOCK; @@ -1235,6 +1236,7 @@ public final class Config } THREADS_PER_INSTANT_THREAD_POOL = serverSettings.getInt("ThreadsPerInstantThreadPool", 2); IO_PACKET_THREAD_CORE_SIZE = serverSettings.getInt("UrgentPacketThreadCoreSize", 2); + THREADS_FOR_LOADING = serverSettings.getBoolean("ThreadsForLoading", false); DEADLOCK_DETECTOR = serverSettings.getBoolean("DeadLockDetector", true); DEADLOCK_CHECK_INTERVAL = serverSettings.getInt("DeadLockCheckInterval", 20); diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/commons/util/IXmlReader.java b/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/commons/util/IXmlReader.java index 4bfed2396e..54bb8b3292 100644 --- a/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/commons/util/IXmlReader.java +++ b/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/commons/util/IXmlReader.java @@ -165,29 +165,47 @@ public interface IXmlReader return false; } - final List> jobs = new CopyOnWriteArrayList<>(); - final File[] listOfFiles = dir.listFiles(); - for (File f : listOfFiles) + if (Config.THREADS_FOR_LOADING) { - if (recursive && f.isDirectory()) + final List> jobs = new CopyOnWriteArrayList<>(); + final File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { - parseDirectory(f, recursive); - } - else if (getCurrentFileFilter().accept(f)) - { - jobs.add(ThreadPool.schedule(() -> + if (recursive && file.isDirectory()) { - parseFile(f); - }, 0)); + parseDirectory(file, recursive); + } + else if (getCurrentFileFilter().accept(file)) + { + jobs.add(ThreadPool.schedule(() -> + { + parseFile(file); + }, 0)); + } + } + while (!jobs.isEmpty()) + { + for (ScheduledFuture job : jobs) + { + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } + } } } - while (!jobs.isEmpty()) + else { - for (ScheduledFuture job : jobs) + final File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { - if ((job == null) || job.isDone() || job.isCancelled()) + if (recursive && file.isDirectory()) { - jobs.remove(job); + parseDirectory(file, recursive); + } + else if (getCurrentFileFilter().accept(file)) + { + parseFile(file); } } } diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java b/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java index 806d00902a..10ae6bca06 100644 --- a/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java +++ b/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java @@ -95,28 +95,44 @@ public class SpawnsData implements IXmlReader } LOGGER.info(getClass().getSimpleName() + ": Initializing spawns..."); - final List> jobs = new CopyOnWriteArrayList<>(); - for (SpawnTemplate template : _spawns) + + if (Config.THREADS_FOR_LOADING) { - if (template.isSpawningByDefault()) + final List> jobs = new CopyOnWriteArrayList<>(); + for (SpawnTemplate template : _spawns) { - jobs.add(ThreadPool.schedule(() -> + if (template.isSpawningByDefault()) { - template.spawnAll(null); - template.notifyActivate(); - }, 0)); + jobs.add(ThreadPool.schedule(() -> + { + template.spawnAll(null); + template.notifyActivate(); + }, 0)); + } } - } - while (!jobs.isEmpty()) - { - for (ScheduledFuture job : jobs) + while (!jobs.isEmpty()) { - if ((job == null) || job.isDone() || job.isCancelled()) + for (ScheduledFuture job : jobs) { - jobs.remove(job); + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } } } } + else + { + for (SpawnTemplate template : _spawns) + { + if (template.isSpawningByDefault()) + { + template.spawnAll(null); + template.notifyActivate(); + } + } + } + LOGGER.info(getClass().getSimpleName() + ": All spawns has been initialized!"); } diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/engines/DocumentEngine.java b/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/engines/DocumentEngine.java index 10f04f4fb3..68302f92da 100644 --- a/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/engines/DocumentEngine.java +++ b/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/engines/DocumentEngine.java @@ -69,26 +69,40 @@ public class DocumentEngine public List loadItems() { final List list = new CopyOnWriteArrayList<>(); - final List> jobs = new CopyOnWriteArrayList<>(); - for (File file : _itemFiles) + + if (Config.THREADS_FOR_LOADING) { - jobs.add(ThreadPool.schedule(() -> + final List> jobs = new CopyOnWriteArrayList<>(); + for (File file : _itemFiles) + { + jobs.add(ThreadPool.schedule(() -> + { + final DocumentItem document = new DocumentItem(file); + document.parse(); + list.addAll(document.getItemList()); + }, 0)); + } + while (!jobs.isEmpty()) + { + for (ScheduledFuture job : jobs) + { + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } + } + } + } + else + { + for (File file : _itemFiles) { final DocumentItem document = new DocumentItem(file); document.parse(); list.addAll(document.getItemList()); - }, 0)); - } - while (!jobs.isEmpty()) - { - for (ScheduledFuture job : jobs) - { - if ((job == null) || job.isDone() || job.isCancelled()) - { - jobs.remove(job); - } } } + return list; } diff --git a/L2J_Mobius_Classic_2.2_Antharas/dist/game/config/Server.ini b/L2J_Mobius_Classic_2.2_Antharas/dist/game/config/Server.ini index 5acff679ce..d036ae7b0f 100644 --- a/L2J_Mobius_Classic_2.2_Antharas/dist/game/config/Server.ini +++ b/L2J_Mobius_Classic_2.2_Antharas/dist/game/config/Server.ini @@ -145,6 +145,10 @@ ThreadsPerInstantThreadPool = 2 # Default: 2 UrgentPacketThreadCoreSize = 2 +# Use threads to decrease startup time. +# Default: False +ThreadsForLoading = False + # --------------------------------------------------------------------------- # Dead Lock Detector (separate thread for detecting deadlocks) diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/Config.java b/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/Config.java index 4069e1357d..2b33efbf5b 100644 --- a/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/Config.java +++ b/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/Config.java @@ -436,6 +436,7 @@ public final class Config public static int INSTANT_THREAD_POOL_COUNT; public static int THREADS_PER_INSTANT_THREAD_POOL; public static int IO_PACKET_THREAD_CORE_SIZE; + public static boolean THREADS_FOR_LOADING; public static boolean DEADLOCK_DETECTOR; public static int DEADLOCK_CHECK_INTERVAL; public static boolean RESTART_ON_DEADLOCK; @@ -1235,6 +1236,7 @@ public final class Config } THREADS_PER_INSTANT_THREAD_POOL = serverSettings.getInt("ThreadsPerInstantThreadPool", 2); IO_PACKET_THREAD_CORE_SIZE = serverSettings.getInt("UrgentPacketThreadCoreSize", 2); + THREADS_FOR_LOADING = serverSettings.getBoolean("ThreadsForLoading", false); DEADLOCK_DETECTOR = serverSettings.getBoolean("DeadLockDetector", true); DEADLOCK_CHECK_INTERVAL = serverSettings.getInt("DeadLockCheckInterval", 20); diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/commons/util/IXmlReader.java b/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/commons/util/IXmlReader.java index 4bfed2396e..54bb8b3292 100644 --- a/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/commons/util/IXmlReader.java +++ b/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/commons/util/IXmlReader.java @@ -165,29 +165,47 @@ public interface IXmlReader return false; } - final List> jobs = new CopyOnWriteArrayList<>(); - final File[] listOfFiles = dir.listFiles(); - for (File f : listOfFiles) + if (Config.THREADS_FOR_LOADING) { - if (recursive && f.isDirectory()) + final List> jobs = new CopyOnWriteArrayList<>(); + final File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { - parseDirectory(f, recursive); - } - else if (getCurrentFileFilter().accept(f)) - { - jobs.add(ThreadPool.schedule(() -> + if (recursive && file.isDirectory()) { - parseFile(f); - }, 0)); + parseDirectory(file, recursive); + } + else if (getCurrentFileFilter().accept(file)) + { + jobs.add(ThreadPool.schedule(() -> + { + parseFile(file); + }, 0)); + } + } + while (!jobs.isEmpty()) + { + for (ScheduledFuture job : jobs) + { + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } + } } } - while (!jobs.isEmpty()) + else { - for (ScheduledFuture job : jobs) + final File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { - if ((job == null) || job.isDone() || job.isCancelled()) + if (recursive && file.isDirectory()) { - jobs.remove(job); + parseDirectory(file, recursive); + } + else if (getCurrentFileFilter().accept(file)) + { + parseFile(file); } } } diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java b/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java index 806d00902a..10ae6bca06 100644 --- a/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java +++ b/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java @@ -95,28 +95,44 @@ public class SpawnsData implements IXmlReader } LOGGER.info(getClass().getSimpleName() + ": Initializing spawns..."); - final List> jobs = new CopyOnWriteArrayList<>(); - for (SpawnTemplate template : _spawns) + + if (Config.THREADS_FOR_LOADING) { - if (template.isSpawningByDefault()) + final List> jobs = new CopyOnWriteArrayList<>(); + for (SpawnTemplate template : _spawns) { - jobs.add(ThreadPool.schedule(() -> + if (template.isSpawningByDefault()) { - template.spawnAll(null); - template.notifyActivate(); - }, 0)); + jobs.add(ThreadPool.schedule(() -> + { + template.spawnAll(null); + template.notifyActivate(); + }, 0)); + } } - } - while (!jobs.isEmpty()) - { - for (ScheduledFuture job : jobs) + while (!jobs.isEmpty()) { - if ((job == null) || job.isDone() || job.isCancelled()) + for (ScheduledFuture job : jobs) { - jobs.remove(job); + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } } } } + else + { + for (SpawnTemplate template : _spawns) + { + if (template.isSpawningByDefault()) + { + template.spawnAll(null); + template.notifyActivate(); + } + } + } + LOGGER.info(getClass().getSimpleName() + ": All spawns has been initialized!"); } diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/engines/DocumentEngine.java b/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/engines/DocumentEngine.java index 10f04f4fb3..68302f92da 100644 --- a/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/engines/DocumentEngine.java +++ b/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/engines/DocumentEngine.java @@ -69,26 +69,40 @@ public class DocumentEngine public List loadItems() { final List list = new CopyOnWriteArrayList<>(); - final List> jobs = new CopyOnWriteArrayList<>(); - for (File file : _itemFiles) + + if (Config.THREADS_FOR_LOADING) { - jobs.add(ThreadPool.schedule(() -> + final List> jobs = new CopyOnWriteArrayList<>(); + for (File file : _itemFiles) + { + jobs.add(ThreadPool.schedule(() -> + { + final DocumentItem document = new DocumentItem(file); + document.parse(); + list.addAll(document.getItemList()); + }, 0)); + } + while (!jobs.isEmpty()) + { + for (ScheduledFuture job : jobs) + { + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } + } + } + } + else + { + for (File file : _itemFiles) { final DocumentItem document = new DocumentItem(file); document.parse(); list.addAll(document.getItemList()); - }, 0)); - } - while (!jobs.isEmpty()) - { - for (ScheduledFuture job : jobs) - { - if ((job == null) || job.isDone() || job.isCancelled()) - { - jobs.remove(job); - } } } + return list; } diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/dist/game/config/Server.ini b/L2J_Mobius_Classic_2.3_SevenSigns/dist/game/config/Server.ini index 79e4606912..469ce38779 100644 --- a/L2J_Mobius_Classic_2.3_SevenSigns/dist/game/config/Server.ini +++ b/L2J_Mobius_Classic_2.3_SevenSigns/dist/game/config/Server.ini @@ -145,6 +145,10 @@ ThreadsPerInstantThreadPool = 2 # Default: 2 UrgentPacketThreadCoreSize = 2 +# Use threads to decrease startup time. +# Default: False +ThreadsForLoading = False + # --------------------------------------------------------------------------- # Dead Lock Detector (separate thread for detecting deadlocks) diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/Config.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/Config.java index 4069e1357d..2b33efbf5b 100644 --- a/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/Config.java +++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/Config.java @@ -436,6 +436,7 @@ public final class Config public static int INSTANT_THREAD_POOL_COUNT; public static int THREADS_PER_INSTANT_THREAD_POOL; public static int IO_PACKET_THREAD_CORE_SIZE; + public static boolean THREADS_FOR_LOADING; public static boolean DEADLOCK_DETECTOR; public static int DEADLOCK_CHECK_INTERVAL; public static boolean RESTART_ON_DEADLOCK; @@ -1235,6 +1236,7 @@ public final class Config } THREADS_PER_INSTANT_THREAD_POOL = serverSettings.getInt("ThreadsPerInstantThreadPool", 2); IO_PACKET_THREAD_CORE_SIZE = serverSettings.getInt("UrgentPacketThreadCoreSize", 2); + THREADS_FOR_LOADING = serverSettings.getBoolean("ThreadsForLoading", false); DEADLOCK_DETECTOR = serverSettings.getBoolean("DeadLockDetector", true); DEADLOCK_CHECK_INTERVAL = serverSettings.getInt("DeadLockCheckInterval", 20); diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/commons/util/IXmlReader.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/commons/util/IXmlReader.java index 4bfed2396e..54bb8b3292 100644 --- a/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/commons/util/IXmlReader.java +++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/commons/util/IXmlReader.java @@ -165,29 +165,47 @@ public interface IXmlReader return false; } - final List> jobs = new CopyOnWriteArrayList<>(); - final File[] listOfFiles = dir.listFiles(); - for (File f : listOfFiles) + if (Config.THREADS_FOR_LOADING) { - if (recursive && f.isDirectory()) + final List> jobs = new CopyOnWriteArrayList<>(); + final File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { - parseDirectory(f, recursive); - } - else if (getCurrentFileFilter().accept(f)) - { - jobs.add(ThreadPool.schedule(() -> + if (recursive && file.isDirectory()) { - parseFile(f); - }, 0)); + parseDirectory(file, recursive); + } + else if (getCurrentFileFilter().accept(file)) + { + jobs.add(ThreadPool.schedule(() -> + { + parseFile(file); + }, 0)); + } + } + while (!jobs.isEmpty()) + { + for (ScheduledFuture job : jobs) + { + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } + } } } - while (!jobs.isEmpty()) + else { - for (ScheduledFuture job : jobs) + final File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { - if ((job == null) || job.isDone() || job.isCancelled()) + if (recursive && file.isDirectory()) { - jobs.remove(job); + parseDirectory(file, recursive); + } + else if (getCurrentFileFilter().accept(file)) + { + parseFile(file); } } } diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java index 806d00902a..10ae6bca06 100644 --- a/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java +++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/gameserver/data/xml/impl/SpawnsData.java @@ -95,28 +95,44 @@ public class SpawnsData implements IXmlReader } LOGGER.info(getClass().getSimpleName() + ": Initializing spawns..."); - final List> jobs = new CopyOnWriteArrayList<>(); - for (SpawnTemplate template : _spawns) + + if (Config.THREADS_FOR_LOADING) { - if (template.isSpawningByDefault()) + final List> jobs = new CopyOnWriteArrayList<>(); + for (SpawnTemplate template : _spawns) { - jobs.add(ThreadPool.schedule(() -> + if (template.isSpawningByDefault()) { - template.spawnAll(null); - template.notifyActivate(); - }, 0)); + jobs.add(ThreadPool.schedule(() -> + { + template.spawnAll(null); + template.notifyActivate(); + }, 0)); + } } - } - while (!jobs.isEmpty()) - { - for (ScheduledFuture job : jobs) + while (!jobs.isEmpty()) { - if ((job == null) || job.isDone() || job.isCancelled()) + for (ScheduledFuture job : jobs) { - jobs.remove(job); + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } } } } + else + { + for (SpawnTemplate template : _spawns) + { + if (template.isSpawningByDefault()) + { + template.spawnAll(null); + template.notifyActivate(); + } + } + } + LOGGER.info(getClass().getSimpleName() + ": All spawns has been initialized!"); } diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/gameserver/engines/DocumentEngine.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/gameserver/engines/DocumentEngine.java index 10f04f4fb3..68302f92da 100644 --- a/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/gameserver/engines/DocumentEngine.java +++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/gameserver/engines/DocumentEngine.java @@ -69,26 +69,40 @@ public class DocumentEngine public List loadItems() { final List list = new CopyOnWriteArrayList<>(); - final List> jobs = new CopyOnWriteArrayList<>(); - for (File file : _itemFiles) + + if (Config.THREADS_FOR_LOADING) { - jobs.add(ThreadPool.schedule(() -> + final List> jobs = new CopyOnWriteArrayList<>(); + for (File file : _itemFiles) + { + jobs.add(ThreadPool.schedule(() -> + { + final DocumentItem document = new DocumentItem(file); + document.parse(); + list.addAll(document.getItemList()); + }, 0)); + } + while (!jobs.isEmpty()) + { + for (ScheduledFuture job : jobs) + { + if ((job == null) || job.isDone() || job.isCancelled()) + { + jobs.remove(job); + } + } + } + } + else + { + for (File file : _itemFiles) { final DocumentItem document = new DocumentItem(file); document.parse(); list.addAll(document.getItemList()); - }, 0)); - } - while (!jobs.isEmpty()) - { - for (ScheduledFuture job : jobs) - { - if ((job == null) || job.isDone() || job.isCancelled()) - { - jobs.remove(job); - } } } + return list; }