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 Fri, 20 Jun 2003 21:34:45 GMT
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.

- 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