Hey folks:
I've been looking at the following two android issues:
https://github.com/j256/ormlite-android/issues/16
https://github.com/j256/ormlite-android/issues/34
After looking at the code and thinking about it a bit, I've realized that you cannot have multiple-threads using dao.callBatchTasks(...) at the same time. I've just added the following to the javadocs for dao.callBatchTasks() and dao.setAutoCommit(...).
NOTE: Depending on your underlying database implementation and whether or not you
are working with a single database connection, you may need to synchronize around
calls to this method otherwise the database transactions that are used may clash
when called simultaneously from multiple threads. Android users need to synchronize.
You may also need to synchronize other calls to transactions and dao.setAutoCommit(...).
I'm not sure if ORMLite should be forcing synchronization here but certainly while the warning is in place, you need to protect this section of code. The problem is that under the covers we are dealing with a single database connection and yet we are doing approximately:
db.startTransaction();
callable.call();
db.endTransaction();
If multiple threads are calling this then transactions race conditions are in effect.
Comments?
gray