]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - src/com/hughes/android/dictionary/engine/TransliteratorManager.java
Fix too course locking that broke startup optimization.
[Dictionary.git] / src / com / hughes / android / dictionary / engine / TransliteratorManager.java
index 0ec81d22a6bc1c7219844227529d11cff5b87b8e..eacab80daac3bd9a5189bbb6433b6dd7c2f99923 100644 (file)
@@ -30,11 +30,18 @@ public class TransliteratorManager {
     // Whom to notify when we're all set up and ready to go.
     private static List<Callback> callbacks = new ArrayList<TransliteratorManager.Callback>();
 
-    public static synchronized Transliterator get(String rules) {
-        Transliterator result = cache.get(rules);
-        if (result == null) {
-            result = Transliterator.createFromRules("", rules, Transliterator.FORWARD);
-            cache.put(rules, result);
+    public static Transliterator get(String rules) {
+        // DO NOT make the method synchronized!
+        // synchronizing on the class would break the whole
+        // asynchronous init concept, since the runnable
+        // then holds the same lock as the init function needs.
+        Transliterator result = null;
+        synchronized (cache) {
+            result = cache.get(rules);
+            if (result == null) {
+                result = Transliterator.createFromRules("", rules, Transliterator.FORWARD);
+                cache.put(rules, result);
+            }
         }
         return result;
     }