A static block is only going to be executed once when the class is first 
accessed.  There is no way in Java that anything can modify the value of testMe 
after the class has been loaded. In fact, as coded, after the static block is 
executed testMe isn't even available any more.

Ralph


On May 15, 2011, at 3:56 PM, venkat veludandi wrote:

> Good afternoon.
> I am using commons configuration as follows:
>  
> commons_configuration.xml:
>  
> <?xml version="1.0" encoding="UTF-8"?>
> <configuration>
>   <properties fileName="test.properties" config-name="test">
>    <reloadingStrategy refreshDelay="30000"
>      
> config-class="org.apache.commons.configuration.reloading.FileChangedReloadingStrategy"/>
>   </properties>
> </configuration>
>  
> ===============================================
> CommonsConfiguration.java
> ----------------------------------------
>  
> public class CommonsConfiguration {
>  
>  
>  private static CombinedConfiguration configuration;
>  
>  
>  static {
>   try {
>    DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(new 
> File("/var/commons_configuration.xml"));
>    configuration = builder.getConfiguration(true);
>   } catch (ConfigurationException e) {
>    e.printStackTrace();
>   }
>  }
>  
>  
>  public static CombinedConfiguration getCombinedConfiguration() {
>   return configuration;
>  }
> }
> =================================================================
> When I use commons configuration as follows in any instance/static method:
>  
> String testMe= (String) 
> CommonsConfiguration.getCombinedConfiguration().getConfiguration("test").getProperty("test.me");
>  
> It work fine with reloading strategy. In other words when I change the 
> test.properties property value, the change gets reflected.
>  
> In some class I was accessing the property in a static block as follows:
> public Sample {
>  static{
>   String testMe = String) 
> CommonsConfiguration.getCombinedConfiguration().getConfiguration("test").getProperty("test.me");
>   //do something
>  }
> }
>  
> If a property is accessed in static block and the property value is changed, 
> the change does not get reflected.
> Is there any work around to access a property in static block and have the 
> property change reflected.
>  
> I appreciate and thank you for your feed back.
>  
> Thanks
> Venkat


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to