vendredi 4 mars 2016

ActiveAndroid.beginTransaction() and multithread

I have multiples lists that I wish to store in my sqlite db in a multithreading fashion using activeAndroid. I run a thread for each list to be persisted.

The body of each thread look like this.

ActiveAndroid.beginTransaction();
try {
   for (MyObjToPersist e : myListOfObjToPersist){
        e.save();
   }
   ActiveAndroid.setTransactionSuccessful();
}
finally {
   ActiveAndroid.endTransaction();
}

The transaction seems to add a lock to the db since each thread run one after the other.

Without using transaction things work as expected but the tasks are pretty slow (a hundred time slowest).

This subject are discuss here.

Anybody know how to avoid this behaviour? Thanks

Aucun commentaire:

Enregistrer un commentaire