db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Rall <...@finemaltcoding.com>
Subject Re: cvs commit: db-torque/src/java/org/apache/torque Torque.java
Date Thu, 26 Jun 2003 06:51:04 GMT
"Henning P. Schmiedehausen" <hps@intermeta.de> writes:

> Daniel Rall <dlr@finemaltcoding.com> writes:
> 
> >The new getMapBuilders() method isn't absolutely thread safe.  Is it
> >used in a thread-safe context, e.g. is the caller synchronized?  If
> >not, one possibility would be to dump the lazy initialization and
> >create the sync'd List in the static field declaration.
> 
> Static field declaration was what brought us here in the first
> place. If you do so, initializing the whole shebang as an Avalon
> Component bombs out with a NPE.

Did the static initialization need to occur earlier in the class
definition, or could the circular reference not be avoided in that
fashion?  (Not that that is the best way to write resilient code.)

> If you add a "synchronized", then you must also make sure
> that the nulling out of the field further down the road isn't racing
> against the getMapBuilders().

Good thought.  Would synchronizing on Torque.class be enough to avoid
that?

> IMHO, the whole static stuff is one of the worst nightmares ever
> conceived by a Java developer and who ever created this place in the
> first place should be sentenced to three to five years of VB.NET.

I too have felt a lot of pain from static initializers.  ;)

The addition of TorqueSingleton doesn't get us out of this situation
by any chance, does it?

- Dan

> >henning@apache.org writes:
> 
> >> henning     2003/06/20 09:59:09
> >> 
> >>   Modified:    src/java/org/apache/torque Torque.java
> >>   Log:
> >>   move access to mapBuilders to an accessor so it will never be null. The
> >>   change to a static init method died with Turbine Component Service.
> >>   
> >>   Revision  Changes    Path
> >>   1.84      +15 -8     db-torque/src/java/org/apache/torque/Torque.java
> >>   
> >>   Index: Torque.java
> >>   ===================================================================
> >>   RCS file: /home/cvs/db-torque/src/java/org/apache/torque/Torque.java,v
> >>   retrieving revision 1.83
> >>   retrieving revision 1.84
> >>   diff -u -r1.83 -r1.84
> >>   --- Torque.java	20 Jun 2003 00:38:40 -0000	1.83
> >>   +++ Torque.java	20 Jun 2003 16:59:09 -0000	1.84
> >>   @@ -176,14 +176,21 @@
> >>         */
> >>        private static List mapBuilders = null;
> >>    
> >>   -    //
> >>   -    // Static initializer
> >>   -    //
> >>   +    /**
> >>   +     * Make sure that the map Builders List is always 
> >>   +     * populated by fetching through a getter
> >>   +     *
> >>   +     * @return A List for the mapBuilders
> >>   +     */
> >>   +    private static List getMapBuilders()
> >>        {
> >>   -        mapBuilders = Collections.synchronizedList(new ArrayList());
> >>   +        if (mapBuilders == null)
> >>   +        {
> >>   +            mapBuilders = Collections.synchronizedList(new ArrayList());
> >>   +        }
> >>   +        return mapBuilders;
> >>        }
> >>    
> >>   -
> >>        /**
> >>         * initialize Torque
> >>         *
> >>   @@ -235,7 +242,7 @@
> >>            initDataSourceFactories(configuration);
> >>    
> >>            isInit = true;
> >>   -        for (Iterator i = mapBuilders.iterator(); i.hasNext();)
> >>   +        for (Iterator i = getMapBuilders().iterator(); i.hasNext();)
> >>            {
> >>                //this will add any maps in this builder to the proper database
map
> >>                BasePeer.getMapBuilder((String) i.next());
> >>   @@ -713,7 +720,7 @@
> >>         */
> >>        public static void registerMapBuilder(String className)
> >>        {
> >>   -        mapBuilders.add(className);
> >>   +        getMapBuilders().add(className);
> >>        }
> >>    
> >>        /**

Mime
View raw message