• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Properties file

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
The fastest and most reliable components of any system are those that are not there. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic