wood burning stoves 2.0
The moose likes Web Services and the fly likes Performance impact loadProperties Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Performance impact loadProperties" Watch "Performance impact loadProperties" New topic

Performance impact loadProperties

Masrudyn Main

Joined: May 13, 2009
Posts: 20
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

Joined: Feb 24, 2006
Posts: 6662

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.

SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
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!

My free books and tutorials: http://www.slideshare.net/krizsan
I agree. Here's the link: http://aspose.com/file-tools
subject: Performance impact loadProperties
It's not a secret anymore!