For getProperty method I’ve created singleton object since during the run there will be a lot of calls to the property file to retrieve a specific value. Thus, one object will be created and persisted in memory during the program run. Alternative is not to make it as singleton: as result FileInputStream object will be created every time this method is called.
From those 2 approaches which one is considered as more appropriate to use in terms of performance?
public static String getProperty (String property) {
if (properties == null) {
try {
FileInputStream fis = new FileInputStream(System.getProperty("user.dir")
+ "//src//main//resources//config.properties");
properties = new Properties();
properties.load(fis);
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
return properties.getProperty(property);
}