My code:
SQLiteDatabase db = ...;
db.beginTransaction();
try{
db.update(...);
db.setTransactionSuccessful();
}finally{
db.endTransaction();
}
Now the problem is that endTransaction occasionally throws SQLiteDatabaseLockedException, and I don't know reason, or how to repeat same exception.
From SQLiteDatabaseLockedException I read:
Thrown if the database engine was unable to acquire the database locks it needs to do its job.
And from beginTransaction I read:
Begins a transaction in EXCLUSIVE mode.
From SQLite manual I read:
An EXCLUSIVE lock is needed in order to write to the database file. Only one EXCLUSIVE lock is allowed on the file and no other locks of any kind are allowed to coexist with an EXCLUSIVE lock. In order to maximize concurrency, SQLite works to minimize the amount of time that EXCLUSIVE locks are held.
So how can DB lock not be acquired in endTransaction when I hold exclusive lock from beginTransaction? Android version where this happens is 4.0.4 (I have crash report, but not able to repeat this).
Need to say that I enabled SQLiteDatabase.enableWriteAheadLogging on the DB, maybe it matters? My app accessess DB in multiple threads.
Anyway, I'd like to get clear explanation, and make simple example that can repeat conditions repeating the problem, so that I can make real fix. Thanks.