views:

213

answers:

4
+1  Q: 

Property file load

I have a web application that reads content from a property file. When will this property file be loaded into memory. ie. Once I deploy the application with some content in the prop file, and after deployment , I change the contents of the prop file, will the changes be reflected or do I have to redeploy?

EDIT : An accessor class' static block reads content from the property file, which is a part of a deployed web application. Now after deployment, i change the property file contents. Will the accessor class read the changes or will it take up the old values?

EDIT2 : when the class is reloaded, will it surely take up the new modified file or rather take up the file cached during deployment(if at all it is cached)

+2  A: 

Assuming that the property file is being loaded by the Properties class, then the property file will be loaded once when the Properties#load() method is called. It will not automatically be reloaded unless your application specifically supports reloading or if your web container restarts the web application during hot deployment.

update: Since the property file is loaded in a static initializer, then the property file will be reloaded when the class is reloaded (e.g. when the web app is hot deployed). If you want to debug this, a simple println() in the static initializer will show you when this happens.

Ken Liu
Ya, thats correct. But what was confusing was that , when the class is reloaded, will it surely take up the new modified file or rather take up the file cached during deployment(if at all it is cached)
Ajay
If you are holding a reference to a Properties object in a class variable (static) then it will be garbage collected when the class is reloaded.
Ken Liu
+1  A: 

It depends on the app server - generally, you'd have to redeploy. But some app servers, in certain configurations may monitor files and kick off a redeploy when they detect file changes. (as an example - I believe Tomcat will automatically redeploy when it detects file changes in exploded deployments.)

Nate
A: 

If this file is loaded by your class than I am pretty sure it won't reload it by it self.

If I were you I would have a separate thread that in given time intervals wakes up, checks whether the file modification date has changed and if it did than reloads it.

ppow
A: 

Apache Commons Configuration provides automatic reloading/saving of file-based configurations.

aslam karachiwala