]> gitweb.fperrin.net Git - Dictionary.git/commitdiff
Fix too course locking that broke startup optimization.
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>
Sun, 19 Mar 2017 19:56:32 +0000 (20:56 +0100)
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>
Sun, 19 Mar 2017 19:56:32 +0000 (20:56 +0100)
Fixes issue #35.

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;
     }