This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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

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: 42958
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.
Have you checked out Aspose?
subject: Properties file
It's not a secret anymore!