File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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 ? -

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:
I agree. Here's the link:
subject: Performance impact loadProperties
jQuery in Action, 3rd edition