Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Performance impact loadProperties

 
Masrudyn Main
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • 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.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • 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.
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • 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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic