Addition of ThreadsForLoading configuration.
This commit is contained in:
		| @@ -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) | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -165,29 +165,47 @@ public interface IXmlReader | ||||
| 			return false; | ||||
| 		} | ||||
| 		 | ||||
| 		final List<ScheduledFuture<?>> jobs = new CopyOnWriteArrayList<>(); | ||||
| 		final File[] listOfFiles = dir.listFiles(); | ||||
| 		for (File f : listOfFiles) | ||||
| 		if (Config.THREADS_FOR_LOADING) | ||||
| 		{ | ||||
| 			if (recursive && f.isDirectory()) | ||||
| 			final List<ScheduledFuture<?>> 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); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
|   | ||||
| @@ -95,28 +95,44 @@ public class SpawnsData implements IXmlReader | ||||
| 		} | ||||
| 		 | ||||
| 		LOGGER.info(getClass().getSimpleName() + ": Initializing spawns..."); | ||||
| 		final List<ScheduledFuture<?>> jobs = new CopyOnWriteArrayList<>(); | ||||
| 		for (SpawnTemplate template : _spawns) | ||||
| 		 | ||||
| 		if (Config.THREADS_FOR_LOADING) | ||||
| 		{ | ||||
| 			if (template.isSpawningByDefault()) | ||||
| 			final List<ScheduledFuture<?>> 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!"); | ||||
| 	} | ||||
| 	 | ||||
|   | ||||
| @@ -69,26 +69,40 @@ public class DocumentEngine | ||||
| 	public List<Item> loadItems() | ||||
| 	{ | ||||
| 		final List<Item> list = new CopyOnWriteArrayList<>(); | ||||
| 		final List<ScheduledFuture<?>> jobs = new CopyOnWriteArrayList<>(); | ||||
| 		for (File file : _itemFiles) | ||||
| 		 | ||||
| 		if (Config.THREADS_FOR_LOADING) | ||||
| 		{ | ||||
| 			jobs.add(ThreadPool.schedule(() -> | ||||
| 			final List<ScheduledFuture<?>> 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; | ||||
| 	} | ||||
| 	 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 MobiusDevelopment
					MobiusDevelopment