android - SQLiteDatabase.endTransaction throws SQLiteDatabaseLockedException -


my code:

sqlitedatabase db = ...; db.begintransaction(); try{    db.update(...);     db.settransactionsuccessful(); }finally{    db.endtransaction(); } 

now problem endtransaction throws sqlitedatabaselockedexception, , don't know reason, or how repeat same exception.

from sqlitedatabaselockedexception read:

thrown if database engine unable acquire database locks needs job.

and begintransaction read:

begins transaction in exclusive mode.

from sqlite manual read:

an exclusive lock needed in order write database file. 1 exclusive lock allowed on file , no other locks of kind allowed coexist exclusive lock. in order maximize concurrency, sqlite works minimize amount of time exclusive locks held.

so how can db lock not acquired in endtransaction when hold exclusive lock begintransaction? android version happens 4.0.4 (i have crash report, not able repeat this).

need enabled sqlitedatabase.enablewriteaheadlogging on db, maybe matters? app accessess db in multiple threads.

anyway, i'd clear explanation, , make simple example can repeat conditions repeating problem, can make real fix. thanks.

imo code correct in singular thread app, must enablewriteaheadlogging related issue. maybe can help:

source

... maximum number of connections used execute queries in parallel dependent upon device memory , possibly other properties.

...

writers should use begintransactionnonexclusive() or begintransactionwithlistenernonexclusive(sqlitetransactionlistener) start transaction. non-exclusive mode allows database file in readable other threads executing queries.

...


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -