Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Properties file

 
Tmmet Johnson
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic