database lock issue in HTC Desire

前端 未结 1 591
南方客
南方客 2021-01-03 10:30

In my application one service is getting data from server and inserting it to table A.

If I go to particular UI, I need to list data from another

相关标签:
1条回答
  • 2021-01-03 11:10

    Try to use one SqliteDatabaseHelper and make it single instance. After that don't close the SqliteDatabase instance after complete your operations.

    You can implement lock on database for that see this

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

    When you start a database operation which has many concurrent operation then you have to use

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

    and after completing operation on database you can use

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

    But if you give error in between transaction then don't set database.setTransactionSuccessful(); so that the transaction will be rollback.

    Also you can check at the time of error whether currently the database is in transaction or not by database.inTransaction(); if it return true then you are in transaction else you are not in transaction

    Also You can check for whether current database has locked or not by calling

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

    this will return Boolean.

    Also you can set whether you want to lock your database if multiple threads are trying to read and write your database at the same time by

    database.setLockingEnabled(boolean);
    

    Above deleted methods are deprecated so please do not use.

    0 讨论(0)
提交回复
热议问题