wood burning stoves
The moose likes Java in General and the fly likes Properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Properties file" Watch "Properties file" New topic

Properties file

Tmmet Johnson
Ranch Hand

Joined: Nov 03, 2004
Posts: 56
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);

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

Joined: Mar 22, 2005
Posts: 42965
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.
I agree. Here's the link: http://aspose.com/file-tools
subject: Properties file
It's not a secret anymore!