2009/3/5 Stuart McCulloch <[email protected]> > 2009/3/5 Niclas Hedhman <[email protected]> > >> I see this snippet of code in ServiceReferenceInstance; >> >> >> private volatile ServiceInstance serviceInstance; >> private CompositeInstance instance; >> >> private CompositeInstance getInstance() >> throws ServiceImporterException >> { >> // DCL that works with Java 1.5 volatile semantics >> if( instance == null ) >> { >> synchronized( this ) >> { >> if( instance == null ) >> { >> serviceInstance = serviceModel.newInstance( module ); >> CompositeInstance providedInstance = >> serviceInstance.instance(); >> >> if( providedInstance.<T>proxy() instanceof Activatable >> ) >> { >> try >> { >> activator.activate( (Activatable) >> providedInstance.proxy() ); >> } >> catch( Exception e ) >> { >> serviceInstance = null; >> throw new ServiceImporterException( e ); >> } >> } >> >> instance = providedInstance; >> } >> } >> } >> >> Is the volatile keyword really on the right variable here?? >> > > doesn't look right to me - the volatile should be on the instance variable > to get the correct semantics >
this is a good overview of the correct semantics: http://jeremymanson.blogspot.com/2008/11/what-volatile-means-in-java.html > > Cheers >> Niclas >> > -- Cheers, Stuart
_______________________________________________ qi4j-dev mailing list [email protected] http://lists.ops4j.org/mailman/listinfo/qi4j-dev

