Thanks Gurkan, 
looks even better now ;)

This was in fact the most pressing gut feeling which I needed to check for 
before we can release 1.0.
I hope that all the random errors I got occasionally under heavy load finally 
vanished now!

LieGrue,
strub



----- Original Message ----
> From: Gurkan Erdogdu <[email protected]>
> To: [email protected]
> Sent: Thu, August 12, 2010 8:53:32 AM
> Subject: Re: svn commit: r984612 - in 
>/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context: 
>AbstractContext.java creational/BeanInstanceBag.java
> 
> Hello Mark
> 
> 
> It seems that your observation is correct! Instead of  using synchronized,I 
>have 
>
> changed with Java 5 style  locking
> 
> Thanks;
> 
> --Gurkan
> 
> 
> ________________________________
> From:  Mark Struberg <[email protected]>
> To: [email protected]
> Sent:  Thu, August 12, 2010 1:55:52 AM
> Subject: Re: svn commit: r984612 - in 
> /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context: 
> AbstractContext.java creational/BeanInstanceBag.java
> 
> Hi  folks!
> 
> since this is pretty heavy stuff, I'd be happy if someone could  review my 
> changes.
> 
> txs and LieGrue,
> strub
> 
> 
> 
> 
> -----  Original Message ----
> > From: "[email protected]" <[email protected]>
> > To: [email protected]
> >  Sent: Thu, August 12, 2010 12:51:26 AM
> > Subject: svn commit: r984612 -  in 
> >/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context: 
> >AbstractContext.java creational/BeanInstanceBag.java
> > 
> >  Author: struberg
> > Date: Wed Aug 11 22:51:26 2010
> > New  Revision:  984612
> > 
> > URL:   http://svn.apache.org/viewvc?rev=984612&view=rev
> > Log:
> > OWB-437  improve  synchronization block for creating new contextual  
>instances
> > 
> > by moving it  to the ContextualBeanBag. This way  only the beanbag will get 
> > locked and not  the whole container  anymore
> > 
> > Modified:
> >      
>>openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java
>a
> >
> >
> >       
>>openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/BeanInstanceBag.java
>a
> >
> >
> > 
> > Modified: 
>>openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java
>a
> >
> >
> >  URL: :  
>>http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java?rev=984612&r1=984611&r2=984612&view=diff
>f
> >
> >
> > 
>==============================================================================
> > ; --- 
>>openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java
>a
> >
> >  a (original)
> > +++  
>>openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java
>a
> >
> >   Wed Aug 11 22:51:26 2010
> > @@ -195,7 +195,7 @@ public abstract  class  AbstractContext im
> >       * {...@inheritdoc} 
> >        */
> >       @SuppressWarnings("unchecked")
> > -     protected synchronized  <T> T getInstance(Contextual<T> contextual,  
> >CreationalContext<T> creationalContext)
> > +     protected  <T> T getInstance(Contextual<T> contextual,  
> >CreationalContext<T> creationalContext)
> >       {
> >           T instance =  null;
> >        
> > @@  -205,9 +205,11 @@  public abstract class AbstractContext im
> >            {
> >                createContextualBag(contextual, creationalContext);
> >            }
> > -        
> > +
> > +          bag =   (BeanInstanceBag<T>)componentInstanceMap.get(contextual);
> >  +
> >           //Look for instance
> > -          instance = 
> >(T)componentInstanceMap.get(contextual).getBeanInstance();         
> >
> > +        instance =   bag.getBeanInstance();
> >          if (instance  !=  null)
> >          {
> >                return instance;
> > @@ -225,16 +227,8  @@ public abstract class  AbstractContext im
> >                    //No instance
> >                    if(instance ==  null)
> >                    {
> > -                      instance = contextual.create(creationalContext);    
> > -                  }
> > -                 
> > -                  //If succesfull creation
> > -                  if (instance != null)
> > -                  {
> > -                      bag =  
> >(BeanInstanceBag<T>)this.componentInstanceMap.get(contextual);
> >  -                       bag.setBeanInstance(instance);
> > +                      instance = bag.create(contextual);     
> >                   }
> > -                
> >               }             
> >           }
> > 
> > 
> > Modified:  
>>openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/BeanInstanceBag.java
>a
> >
> >
> >  URL: 
>>http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/BeanInstanceBag.java?rev=984612&r1=984611&r2=984612&view=diff
>f
> >
> >
> > 
>==============================================================================
> > ; --- -  
>>openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/BeanInstanceBag.java
>a
> >
> >   (original)
> > +++  
>>openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/BeanInstanceBag.java
>a
> >
> >   Wed Aug 11 22:51:26 2010
> > @@ -18,6 +18,7 @@
> >    */
> >  package  org.apache.webbeans.context.creational;
> > 
> > +import  javax.enterprise.context.spi.Contextual;
> >   import  javax.enterprise.context.spi.CreationalContext;
> >   import java.io.Serializable;
> > 
> > @@ -25,7  +26,7 @@  public class BeanInstanceBag<T> implemen
> >   {
> >      private  final CreationalContext<T>  beanCreationalContext;
> >    
> > -    private  volatile T beanInstance;
> > +    private T   beanInstance;
> >    
> >      public   BeanInstanceBag(CreationalContext<T> beanCreationalContext)
> >        {
> > @@ -58,4 +59,19 @@ public class  BeanInstanceBag<T>  implemen
> >           return beanInstance;
> >       }
> > 
> >  +    /**
> > +     * Create the contextual  instance  in a thread safe fashion
> > +     * @param  contextual
> > +      * @return the single contextual  instance for the context
> > +      */
> > +     public synchronized T create(Contextual<T>  contextual)
> >  +    {
> > +        // we need to  check  again, maybe we got blocked by a previous 
> >invocation
> > +          if (beanInstance == null)
> > +          {
> > +            beanInstance  =  contextual.create(beanCreationalContext);
> > +          }
> > +
> > +        return beanInstance; 
> > +     }
> >  }
> > 
> > 
> > 
> 
> 


      

Reply via email to