Daniel Rall <[EMAIL PROTECTED]> 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.
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().
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.
Regards
Henning
>- Dan
>[EMAIL PROTECTED] 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);
>> }
>>
>> /**
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
--
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen INTERMETA GmbH
[EMAIL PROTECTED] +49 9131 50 654 0 http://www.intermeta.de/
Java, perl, Solaris, Linux, xSP Consulting, Web Services
freelance consultant -- Jakarta Turbine Development -- hero for hire
--- Quote of the week: "Never argue with an idiot. They drag you down
to their level, then beat you with experience." ---
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]