I am using these statements to load java program properties at runtime.
public static void Init(String confFile) {
try {
prop.load(new FileInputStream(confFile));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Same class has the following method for reading properties
public static String GetProperty(String key) {
return prop.getProperty(key);
}
My question is, if I call Init and GetProperty simultaneously without the synchronized block will it cause a problem?
I read this java Properties . here it says that the getProperty method is thread safe. yes, I know this, because I have been using it with multiple threads, but now while one thread is loading new properties and others are calling the getProperty method I think it can cause problems
Yes, it is threadsafe.
Properties extends Hashtable, which is threadsafe. load() methods are synchronizedHashtableIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With