diff options
author | 2015-02-17 15:12:05 -0800 | |
---|---|---|
committer | 2015-02-19 11:40:57 -0800 | |
commit | 0b03f13cabec84d2d841fde47ce9fec0d531b6a1 (patch) | |
tree | 5cc14dea6693025f25d279dd59140c04d0d7495f /java/src/com/android/inputmethod/latin/spellcheck/UserDictionaryLookup.java | |
parent | 95711bfcee07d848883316cf07439408f5b332a1 (diff) | |
download | latinime-0b03f13cabec84d2d841fde47ce9fec0d531b6a1.tar.gz latinime-0b03f13cabec84d2d841fde47ce9fec0d531b6a1.tar.xz latinime-0b03f13cabec84d2d841fde47ce9fec0d531b6a1.zip |
Sanitize the usage of executors.
There should be 1 executor each for static and dynamic language models.
This prevents too many dynamic LM updates from running in parallel,
competing for resources.
Change-Id: I8ec439e0ea2d92fba275bc20a0b8c9193346a0c1
Diffstat (limited to 'java/src/com/android/inputmethod/latin/spellcheck/UserDictionaryLookup.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/spellcheck/UserDictionaryLookup.java | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/UserDictionaryLookup.java b/java/src/com/android/inputmethod/latin/spellcheck/UserDictionaryLookup.java index baff8f066..19620511d 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/UserDictionaryLookup.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/UserDictionaryLookup.java @@ -26,14 +26,13 @@ import android.util.Log; import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.latin.common.LocaleUtils; +import com.android.inputmethod.latin.utils.ExecutorUtils; import java.io.Closeable; import java.util.ArrayList; import java.util.HashMap; import java.util.Locale; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -83,12 +82,6 @@ public class UserDictionaryLookup implements Closeable { private final ContentResolver mResolver; /** - * Executor on which to perform the initial load and subsequent reloads (after a delay). - */ - private final ScheduledExecutorService mLoadExecutor = - Executors.newSingleThreadScheduledExecutor(); - - /** * Runnable that calls loadUserDictionary(). */ private class UserDictionaryLoader implements Runnable { @@ -150,7 +143,8 @@ public class UserDictionaryLookup implements Closeable { } // Schedule a new reload after RELOAD_DELAY_MS. - mReloadFuture = mLoadExecutor.schedule(mLoader, RELOAD_DELAY_MS, TimeUnit.MILLISECONDS); + mReloadFuture = ExecutorUtils.getExecutorForDynamicLanguageModelUpdate().schedule( + mLoader, RELOAD_DELAY_MS, TimeUnit.MILLISECONDS); } } private final ContentObserver mObserver = new UserDictionaryContentObserver(); @@ -192,7 +186,8 @@ public class UserDictionaryLookup implements Closeable { // Schedule the initial load to run immediately. It's possible that the first call to // isValidWord occurs before the dictionary has actually loaded, so it should not // assume that the dictionary has been loaded. - mLoadExecutor.schedule(mLoader, 0, TimeUnit.MILLISECONDS); + ExecutorUtils.getExecutorForDynamicLanguageModelUpdate().schedule( + mLoader, 0, TimeUnit.MILLISECONDS); // Register the observer to be notified on changes to the UserDictionary and all individual // items. @@ -236,9 +231,6 @@ public class UserDictionaryLookup implements Closeable { Log.d(TAG, "Close called (no pun intended), cleaning up executor and observer"); } if (mIsClosed.compareAndSet(false, true)) { - // Shut down the load executor. - mLoadExecutor.shutdown(); - // Unregister the content observer. mResolver.unregisterContentObserver(mObserver); } @@ -342,8 +334,7 @@ public class UserDictionaryLookup implements Closeable { if (DEBUG) { Log.d(TAG, "Loading UserDictionary"); } - HashMap<String, ArrayList<Locale>> dictWords = - new HashMap<String, ArrayList<Locale>>(); + HashMap<String, ArrayList<Locale>> dictWords = new HashMap<>(); // Load the UserDictionary. Request that items be returned in the default sort order // for UserDictionary, which is by frequency. Cursor cursor = mResolver.query(UserDictionary.Words.CONTENT_URI, @@ -413,7 +404,7 @@ public class UserDictionaryLookup implements Closeable { Log.d(TAG, "Word [" + dictWord + "] not seen for other locales, creating new entry"); } - dictLocales = new ArrayList<Locale>(); + dictLocales = new ArrayList<>(); dictWords.put(dictWord, dictLocales); } // Append the locale to the list of locales this word is in. |