RE: JavaMemoryModel: Re: TheServerSide.com: EJBean Class Initiali zation Hooks

From: David Holmes (dholmes@dstc.edu.au)
Date: Sun Jun 24 2001 - 19:02:45 EDT


> public abstract class AbstractEJBean
> {
>
> private static classInited= false;
>
> final protected void onSetEJBContext()
> {
> synchronized(getClass()) {
> if (!classInited) {
> initializeOncePerBeanClass();
> classInited= true;
> }
> }
> initializeOncePerInstance();
> }
> }

The call to getClass() will return a different class object for each
subclass, thus causing synchronization on a different object. Even if there
should only be a single subclass the general rule for shared statics is to
always synchronize on the class object in which the static was declared - in
this case AbstractEJBean.class

Cheers,
David Holmes
-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel



This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:32 EDT