SQLite transaction behaviour using greendao

ε祈祈猫儿з 提交于 2020-01-16 11:25:46

问题


I am using greendao as ORM library in my Android project and have problems understanding the behaviour of transactions.

greendao offers an API runInTx(Runnable r) . My question is, how will two calls of this method from different Threads will be handled?

Thread 1

public void thread1() {
    DaoManager.INSTANCE.getDaoSession().runInTx(new Runnable()
    {
        doQueries();
        doInsertsAndUpdates();
    }
}

Thread 2

public void thread2() {
      DaoManager.INSTANCE.getDaoSession().runInTx(new Runnable()
    {
        doQueries();
        doInsertsAndUpdates();
    }
} 

I have seen, that runInTx is calling SQLiteDatabase.beginTransaction in exclusive mode, so no other thread can read/write to database while this transaction is open. But what i cannot figure out is, when thread1 is doing his job (i.e. doQueries) will the other thread (i.e thread2) blocked, so doQueries and doInsertsAndUpdates of thread2 will not be performed until thread1 has finished the transaction?

Thanks for any help.


回答1:


SQLiteDatabase.beginTransaction is a blocking call.



来源:https://stackoverflow.com/questions/29227054/sqlite-transaction-behaviour-using-greendao

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!