Assuming 2 users access a @EJB remote ejb and try to invoke
ResourceBean.createInstance() to get a instance of the bean. Since the
method is not synchronized, the following statement in the method could
cause 2 instances assigned to the same variable of ResourceBean class under
some execution order, and later set into
ResourceProxyHandler(... this.actualResourceReference).

user1:            this.actualResourceReference =
resourceService.getResourceReference(this.resourceReference);
user2:            this.actualResourceReference =
resourceService.getResourceReference(this.resourceReference);
....
User1:          setHandler(new
ResourceProxyHandler(this,this.actualResourceReference));
User2:          setHandler(new
ResourceProxyHandler(this,this.actualResourceReference));

This could cause 2 users sharing the same remote ejb instance.
Probably, actualResourceReference should be a local variable of the method
instead of a variable of ResourceBean.



On Wed, Oct 27, 2010 at 10:34 AM, Gurkan Erdogdu <[email protected]>wrote:

> ResourceBeans are dependent, so every reference gets new bean instance.
>
>
> Could you give some example?
>
>
>
> ----- Original Message ----
> From: YING WANG <[email protected]>
> To: [email protected]
> Sent: Wed, October 27, 2010 4:54:34 PM
> Subject: actualResourceReference in ResourceBean should be a local variable
> in
> createInstance method?
>
> Does anyone know why we use the normal field variable to store the actual
> resource reference in ResourceBean?
> Considering 2 threads try to create resource bean instance at same time,
> there is a chance that 2 threads access the same actual reference in
> ResourceBean.createInstance() method.
>
> thanks in advance...
> Ying
>
>
>
>

Reply via email to