Android threading and database locking

后端 未结 7 1755
夕颜
夕颜 2020-12-07 10:31

We are using AsyncTasks to access database tables and cursors.

Unfortunately we are seeing occasional exceptions regarding the database being locked.

7条回答
  •  猫巷女王i
    2020-12-07 11:02

    Are you talking of a single user action that, inside your program, causes multiple threads to be run, more than one of which may be accessing the database in update mode ?

    That's bad design, period. There is no way for you to know in which order the threads will be scheduled by your OS (/VM), and therefore there is no way for you to know in which order the database accesses will happen, and that is very likely to imply that there is no way for you to know that database accesses will always happen in the order that you are expecting.

    All database accesses generated by/coming from some user action should all be done in one single thread.

提交回复
热议问题