Hi, I want to load a properties file. Below is the code that I have.I have synchronized at the method level?I know this will slow down the performance.How can I set the synchronization at the block level?Can anyone help me out?
public synchronized Properties getPropertyFile(String fileName)throws Exception {
Properties prop = (Properties) hashMap.get(fileName); if(prop == null){ prop = new Properties(); InputStream is = null; is = this.getClass().getClassLoader().getResourceAsStream(fileName); prop.load(is); map.put(fileName,prop); is.close(); }
I have the below member variables and methods. private static HashMap hashMap = new HashMap(); private static PropertyUtils instance = new PropertyUtils(); private PropertyUtility() {} public static PropertyUtility instance() {return instance;} Thanks in advance,
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
I wouldn't worry about making synchronization more fine-grained. File I/O is inherently slow compared to in-memory operations, so the overhead of synchronization should be negligible.