问题
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