title: Commons Configuration2 ReloadingFileBasedConfiguration
body: <p>I am trying to implement the Apache Configuration 2 in my codebase</p>
  
  <pre><code>import java.io.File;
  import java.util.concurrent.TimeUnit;
  
  import org.apache.commons.configuration2.PropertiesConfiguration;
  import org.apache.commons.configuration2.builder.ConfigurationBuilderEvent;
  import org.apache.commons.configuration2.builder.ReloadingFileBasedConfigurationBuilder;
  import org.apache.commons.configuration2.builder.fluent.Parameters;
  import org.apache.commons.configuration2.convert.DefaultListDelimiterHandler;
  import org.apache.commons.configuration2.event.EventListener;
  import org.apache.commons.configuration2.ex.ConfigurationException;
  import org.apache.commons.configuration2.reloading.PeriodicReloadingTrigger;
  
  import org.apache.commons.configuration2.CompositeConfiguration;
  
  public class Test {
  
      private static final long DELAY_MILLIS = 10 * 60 * 5;
  
  
      public static void main(String[] args) {
          // TODO Auto-generated method stub
          CompositeConfiguration compositeConfiguration = new CompositeConfiguration();
          PropertiesConfiguration props = null;
          try {
              props = initPropertiesConfiguration(new File("/tmp/DEV.properties"));
          } catch (ConfigurationException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
          compositeConfiguration.addConfiguration( props );
          compositeConfiguration.addEventListener(ConfigurationBuilderEvent.ANY,
                  new EventListener&lt;ConfigurationBuilderEvent&gt;()
                  {
                      @Override
                      public void onEvent(ConfigurationBuilderEvent event)
                      {
                          System.out.println("Event:" + event);
  
                      }
                  });
  
          System.out.println(compositeConfiguration.getString("property1"));
  
          try {
              Thread.sleep(14*1000);
          } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
          // Have a script which changes the value of property1 in DEV.properties
          System.out.println(compositeConfiguration.getString("property1"));
      }
  
      protected static PropertiesConfiguration initPropertiesConfiguration(File propsFile) throws ConfigurationException { 
  
          if(propsFile.exists()) {
  
              final ReloadingFileBasedConfigurationBuilder&lt;PropertiesConfiguration&gt; builder =
                      new ReloadingFileBasedConfigurationBuilder&lt;PropertiesConfiguration&gt;(PropertiesConfiguration.class)
                      .configure(new Parameters().fileBased()
                          .setFile(propsFile)
                          .setReloadingRefreshDelay(DELAY_MILLIS)
                          .setThrowExceptionOnMissing(false)
                          .setListDelimiterHandler(new DefaultListDelimiterHandler(';')));
              final PropertiesConfiguration propsConfiguration = builder.getConfiguration();
              PeriodicReloadingTrigger trigger = new PeriodicReloadingTrigger(builder.getReloadingController(),
                      null, 1, TimeUnit.SECONDS);
                  trigger.start();
  
              return propsConfiguration;
          } else {
              return new PropertiesConfiguration();
          }
  
      }
  }
  </code></pre>
  
  <p>Here is a sample code that I using to check whether the Automatic Reloading works or not. However when the underlying property file is updated, the configuration doesn't reflect it.</p>