I have an application which loads the proeprties from file and use them in code, and some times we have to change the properties at regular intervals, in this case every time we have to stop and start the server. This will be a hectic job to rebooting the server in each time. Is there any clue how to read properties at run time even after we change the file?
a naive approach could be to have a background task which reads the properties file at regular intervals and checks for changed properties.
A more efficient solution could be to install an event listener to monitor the properties file for changes and only re-read it in case there was a modification. You could for example use Apache Commons VFS which supports listeners for all kind of virtual file system, i.e. local file systems, too.
From the original post I'd guess it's a regular properties file!
But it's still unclear if we're talking about a web application or perhaps an own server-like application?!? Bill's idea with a servlet would be a great idea but I'm not sure if "server" is a servlet container or kind of server application... This information would really be helpful to give good advices for a solution
I'd prefer these solutions, too. Unfortunately I don't know how reliable a listener on the file system is in Java. Anyway, even if such a listener would not work as expected Bill's suggestion would be a perfect solution for a web application in any case.
I'm assuming you only have a few applications that access this properties file, otherwise, what I'm about to say below may not make sense.
If you're manually modifying the properties file in a text editor, why not just add a quick web page form on one of your applications (with maybe a quick, hard-coded admin password that only certain people know), and then modify the properties file using that? The Properties file has store() and load() methods and you have it loaded in memory already, so the doing this as a JSP page theoretically wouldn't be too horrible. Then the app itself knows that something changed.
If another application is modifying the properties file, then why not have that application just open a quick HTTP connection to a special URL, like http://host/servlet/app/refreshMe.jsp or whatever, and whenever that application updates the properties file, it hits that URL to tell the other application(s) to reload the properties file. You could also hit this URL in a web browser if you're manually modifying the file. This is the quick and dirty idea. There are more formal ways to do this with web services, with a central web service that then goes and updates all the other apps, etc. etc., but it sounds like you may not need that.