harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexei Zakharov" <alexei.zakha...@gmail.com>
Subject Re: [Approval] Commit Harmony-5460
Date Tue, 19 Feb 2008 10:16:42 GMT
Hi Tony,

Don't you think that placing a synchronized block around the existing
code would be a more transparent fix rather than simply redirecting
all job to ICU? I mean something like this:

Index: src/main/java/java/text/MessageFormat.java
===================================================================
--- src/main/java/java/text/MessageFormat.java  (revision 628711)
+++ src/main/java/java/text/MessageFormat.java  (working copy)
@@ -446,6 +446,8 @@
      *                when the pattern cannot be parsed
      */
     public static String format(String template, Object... objects) {
+        String result;
+
         if (objects != null) {
             for (int i = 0; i < objects.length; i++) {
                 if (objects[i] == null) {
@@ -453,12 +455,16 @@
                 }
             }
         }
-        if (format == null) {
-            format = new com.ibm.icu.text.MessageFormat(template);
-        } else if (!template.equals(format.toPattern())){
-            format.applyPattern(template);
+        synchronized (MessageFormat.class) {
+            if (format == null) {
+                format = new com.ibm.icu.text.MessageFormat(template);
+            } else if (!template.equals(format.toPattern())){
+                format.applyPattern(template);
+            }
+            result = format.format(objects);
         }
-        return format.format(objects);
+
+        return result;
     }

     /**


Thanks,
Alexei

2008/2/19, Tony Wu <wuyuehao@gmail.com>:
> This is a major problem which blocks MessageFormat running on
> multi-thread platform. It fails because the caching in Harmony does
> not work with ICU4j 3.8.1. I suggest to commit this patch for M5.
>
> --
> Tony Wu
> China Software Development Lab, IBM
>

Mime
View raw message