From: Reimar Döffinger Date: Sun, 19 Mar 2017 19:56:32 +0000 (+0100) Subject: Fix too course locking that broke startup optimization. X-Git-Url: http://gitweb.fperrin.net/?p=Dictionary.git;a=commitdiff_plain;h=24e9e80d611f03d4bc75871bf6cff5fe227b4ee3 Fix too course locking that broke startup optimization. Fixes issue #35. --- diff --git a/src/com/hughes/android/dictionary/engine/TransliteratorManager.java b/src/com/hughes/android/dictionary/engine/TransliteratorManager.java index 0ec81d2..eacab80 100644 --- a/src/com/hughes/android/dictionary/engine/TransliteratorManager.java +++ b/src/com/hughes/android/dictionary/engine/TransliteratorManager.java @@ -30,11 +30,18 @@ public class TransliteratorManager { // Whom to notify when we're all set up and ready to go. private static List callbacks = new ArrayList(); - 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; }