• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Performance impact loadProperties

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My web service needs to read configurable parameters from a configuration file. This is done by a properties file which is called by loadProperties. This is done for every web service call.

Is there a better way to do this - for example to load the config at start up and is cached so that every web service call do not need to read from the properties file?

How can I do this? Is there a better way/technique? Thanks.
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The java.util.Properties class (assuming that is what you used) extends a HashMap and should by itself serve as a cache of sorts. Are you referring to the load method ? - http://download.oracle.com/javase/6/docs/api/java/util/Properties.html#load(java.io.Reader)

File IO is an expensive operation. You can look at the last modified time of a file and cache that too. If the last modified time has not changed, do not reload the file.

You can also configure a Timer and TimerTask to poll the file ever X seconds and perform this operation. That will reduce the overhead even more, but will introduce a latency of X seconds for every property change.
 
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
As you yourself say, caching is a good idea, provided that the properties in the file does not change.
Alternatively, another suggestion is to "implement" the property file as a Groovy script or have a Groovy script read the property file when the Groovy script is modified.
Spring has a mechanism for periodic checking of Groovy scripts and reloading of these upon modification.
Such a bean is declared along these lines:

Best wishes!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic