How to reload property file in java at runtime?

I have found a good utility class which is part of the apache configuration jar to reload the property or resource file without restarting the JVM or Application Server. FileChangedReloadingStrategy class can be used to reload the property/resource file at runtime if there is any modification is done in the property file.

In the below given example I have used the FileChangedReloadingStrategy.

You may set appropriate refresh delay to FileChangedReloadingStrategy to reduce the IO operation.

Four implementations for ReloadingStrategy are provided by the apache configuration API.

  1. FileChangedReloadingStrategy
  2. InvariantReloadingStrategy
  3. ManagedReloadingStrategy
  4. VFSFileChangedReloadingStrategy

You may also write your own implementation of property file reload strategy through giving an implementation for org.apache.commons.configuration.reloading.ReloadingStrategy interface.

Sample Program

Apache Common Configuration API

Leave a comment

Your email address will not be published. Required fields are marked *