I am very much confused regarding access to SQLiteDatabase
. Either it should be one connection or multiple connections to have access from multiple threads. I have read many articles including following two.
https://mcmap.net/q/63390/-how-can-i-avoid-concurrency-problems-when-using-sqlite-on-android http://touchlabblog.tumblr.com/post/24474398246/android-sqlite-locking
Both of these recommends to have single connection. Even my own answer to same question was accepted by OP. I used the Singleton
approach to access SQLiteopenHelper
class.
https://mcmap.net/q/885084/-best-way-to-access-database-in-multi-threaded-application-android
But I am still confused after reading documentation of enableWriteAheadLogging
which states
This method enables parallel execution of queries from multiple threads on the same database. It does this by opening multiple connections to the database and using a different database connection for each query. The database journal mode is also changed to enable writes to proceed concurrently with reads.
Now this is the confusing part. If I want to access database from simultaneous multiple threads, I have Singleton
access to SQLiteOpenHelper
which in my understanding means the serial execution of insertions while Simultaneous reads can be done with no-errors. But above documentation says, in order to have Simultaneous access, enableWriteAheadLogging
should be called which in returns create multiple connections. What is this going on?? What does it mean if I do insertions by calling getWritableDatabase()
using Singleton SQLiteOpenHelper
from multiple threads? Will the calls be serial? Should enableWriteAheadLogging
be called?
Please clarify.