[concurrency-interest] Visibility of lazy intialisation

Rémi Forax forax at univ-mlv.fr
Wed Jul 19 03:19:43 EDT 2006


Jan Nielsen a écrit :
> Mike,
>
> For lazy initialization of singletons, consider using the Initialization 
> on Demand Holder Idiom:
>
>   http://en.wikipedia.org/wiki/Initialization_on_Demand_Holder_Idiom
>
> -Jan
>   
It's perhaps off topic but the code of the example can be improved.
The field LazyHolder.something doesn't need a public visibility
and is not declared final.

public class Something {
     private Something() {
     }
     
     private static class LazyHolder  {
       static final Something something = new Something();
     }
     
     public static Something getInstance() {
         return LazyHolder.something;
     }
 }

Rémi Forax



More information about the Concurrency-interest mailing list