Database lock issue on HTC Desire

In my application, one service receives data from the server and inserts it into table A

If I go to a specific user interface, I need to list data from another table B , if the background operation does this will throw a database lock exception. I have two databases, the operation is performed parallel to each other on two different tables.

It works fine on samsung gt15801. But htc wants it to block the database error.

HTC Desire - The insertion process takes 91 seconds.

Samsung gt15801 - the insertion process takes 21 seconds.

+3
android database concurrency locking transactions
Aug 05 2018-11-11T00:
source share
1 answer

Try using one SqliteDatabaseHelper and make it a single instance. After that, do not close the SqliteDatabase instance after operations are complete .

You can implement a lock in the database to see this

http://www.sqlite.org/lockingv3.html

When starting an operation with a database that has many simultaneous operations, you should use

 database.beginTransaction(); /* for start transaction */ 

and after completing the database you can use

 database.setTransactionSuccessful(); database.endTransaction(); 

But if you give an error between transactions, then do not set database.setTransactionSuccessful(); so that the transaction is rollback.

You can also check during an error whether the database is currently in a transaction or not, database.inTransaction(); if it returns true, then you are in a transaction, otherwise you are not in a transaction

You can also check if the current database is locked or not by calling

 database.isDbLockedByCurrentThread(); database.isDbLockedByOtherThreads(); 

this will return a boolean value.

You can also set whether you want to lock your database if several threads are trying to read and write your database at the same time.

 database.setLockingEnabled(boolean); 

The above methods are deprecated, so please do not use.

+14
Aug 05 2018-11-11T00:
source share



All Articles