commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephen Colebourne <scolebou...@btopenworld.com>
Subject Re: [lang] LazyInitializer
Date Mon, 26 Oct 2009 08:47:37 GMT
Oliver Heger wrote:
> Do you think that a generic implementation of the lazy initialization 
> pattern has such an impact on performance?
> 
> In a typical implementation you would add the initializer as a final 
> member field to a class:
> 
> public class MyClass {
>     private final MyConcreteLazyInitializer init =
>         new MyConcreteLazyInitializer();
> }
> 
> The initializer instance has to be created once. Then, on each access to 
> the object managed by the initializer you have to call init.get() 
> instead of accessing the volatile field directly.
> 
> Perhaps we should run some benchmarks to find out whether this 
> difference really matters?

Writing benchmarks for this kind of thing would be very difficult I 
suspect, and subject to JVM and GC.

One point about this object is that it will be long-lived - the 
initializer will live as long as the instance of the parent object. This 
will certainly have some GC impact.

Maybe it comes down to a question of whether I personally would use this 
approach. I wouldn't, firstly because lazy initialization is so rare, 
and secondly because in those cases I'd prefer to inline the code.

Stephen

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message