*/
private boolean mInitialized = false;
+ private final Object mInitializedLock = new Object();
+
/**
* Create an instance of HttpAuthDatabase for the named file, and kick-off background
* initialization of that database.
* @param context the Context to use for opening the database
* @param databaseFile Name of the file to be initialized.
*/
- private synchronized void initOnBackgroundThread(Context context, String databaseFile) {
- if (mInitialized) {
- return;
- }
+ private void initOnBackgroundThread(Context context, String databaseFile) {
+ synchronized (mInitializedLock) {
+ if (mInitialized) {
+ return;
+ }
- initDatabase(context, databaseFile);
+ initDatabase(context, databaseFile);
- // Thread done, notify.
- mInitialized = true;
- notifyAll();
+ // Thread done, notify.
+ mInitialized = true;
+ mInitializedLock.notifyAll();
+ }
}
/**
* @return true if the database was initialized, false otherwise
*/
private boolean waitForInit() {
- synchronized (this) {
+ synchronized (mInitializedLock) {
while (!mInitialized) {
try {
- wait();
+ mInitializedLock.wait();
} catch (InterruptedException e) {
Log.e(LOGTAG, "Caught exception while checking initialization", e);
}