Optimize world config retrieval.

This commit is contained in:
asofold 2012-09-17 20:52:13 +02:00
parent dc0aa6bf28
commit a79cd3f6f2

View File

@ -132,7 +132,14 @@ public class ConfigManager {
public static ConfigFile getConfigFile(final String worldName) {
final ConfigFile configFile = worldsMap.get(worldName);
if (configFile != null) return configFile;
return getConfigFile();
// Expensive only once, for the rest of runtime the file is returned fast.
synchronized(ConfigManager.class){
// Need to check again.
if (worldsMap.containsKey(worldName)) return worldsMap.get(worldName);
final ConfigFile globalConfig = getConfigFile();
worldsMap.put(worldName, globalConfig);
return globalConfig;
}
}
/**