mercredi 29 avril 2015

In Android which line of code throws SQLiteDatabaseLockedException exception

I want to know which class and which method in Android SDK throws this exception "SQLiteDatabaseLockedException" with message "database is locked".

Recently I had encountered SQLiteDatabaseLockedException while accessing the SQLite database from multiple threads.

After searching on the internet and reading about SQLite Locking and multithreading support, I solve it by making a singleton SQLiteOpenHelper instance.

But I want to know how the things are working in background. I had gone through the source code of classes SQLiteOpenHelper and SQLiteDatabase. The SQLiteOpenHelper has an instance of SQLiteDatabase, which iteself maintains a lock by using an Object "mLock". Both these classes are Thread-safe as the methods are synchronized (or using synchronized block).

I did not find any line which says "throw new SQLiteDatabaseLockedException("database is locked). I also read the classes which are refered in SQLiteDatabase like SQLiteConnection, SQLiteConnectionPool, but did'nt find anything useful. I read somewhere on the internet that SQLite maintains its internal locking. Is it means the native libraries of SQLite?

Please someone explains in depth what is happening behind the secenes. Thanks.

Aucun commentaire:

Enregistrer un commentaire