title: Create Singleton with function/constructor arguments (usefull for e.g. injection)
body: <p>We use spring to construct/inject our java beans. Here a snippet:</p>
  
  <pre><code>&lt;bean id="myAppConfigs" class="my.cool.webapp.ApplicationConfig" scope="singleton"&gt;
      &lt;constructor-arg value="8080" /&gt;
      &lt;constructor-arg value="MyAppName1" /&gt; 
  &lt;/bean&gt;
  </code></pre>
  
  <p>We use the singleton-pattern in </p>
  
  <pre><code>public static ApplicationConfig getCurrentInstance(ServletContext sctx) {
      if (instance == null) {
                  WebApplicationContext wac = null;
                  if (sctx != null) {
                      wac = WebApplicationContextUtils.getWebApplicationContext(sctx);
                  }
  return (ApplicationConfig) wac.getBean("myAppConfigs");
  </code></pre>
  
  <p>Since the bean is only reading some properties which are always the same I doubt there could be problems. But I'm still curious for a nice thread safe way to implement it
  There is of course the <a href="http://en.wikipedia.org/wiki/Double-checked_locking#Usage_in_Java" rel="nofollow">Double Checked Locking with usage of volatile</a> which is  threadsafe. 
  But is there another way maybe to use the <a href="http://en.wikipedia.org/wiki/Initialization_on_demand_holder_idiom" rel="nofollow">Initialization on demand holder idiom </a> together with function/constructor arguments?</p>