My code have include a synchronization mechanism when it read/write database in multi-threaded environment.
gradle version:3.4
Android studio version:2.3
The key info of build.gradle file is as follows:
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
useLibrary ‘org.apache.http.legacy’
defaultConfig {
//dex 65535
multiDexEnabled true
}
The crash log is as follows:
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:304)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: net.sqlcipher.database.SQLiteException: database is locked: BEGIN EXCLUSIVE;
at net.sqlcipher.database.SQLiteDatabase.native_execSQL(Native Method)
at net.sqlcipher.database.SQLiteDatabase.execSQL(SQLiteDatabase.java:2265)
at net.sqlcipher.database.SQLiteDatabase.beginTransactionWithListener(SQLiteDatabase.java:706)
at net.sqlcipher.database.SQLiteDatabase.beginTransaction(SQLiteDatabase.java:658)
at com.pos.xwpos.db.DBFactory.saveroleRightGroup(DBFactory.java:4959)
at com.pos.xwpos.task.GetMerrightsetsTask.doInBackground(GetMerrightsetsTask.java:133)
at com.pos.xwpos.task.GetMerrightsetsTask.doInBackground(GetMerrightsetsTask.java:36)
at android.os.AsyncTask$2.call(AsyncTask.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
… 3 more
net.sqlcipher.database.SQLiteException: database is locked: BEGIN EXCLUSIVE;
at net.sqlcipher.database.SQLiteDatabase.native_execSQL(Native Method)
at net.sqlcipher.database.SQLiteDatabase.execSQL(SQLiteDatabase.java:2265)
at net.sqlcipher.database.SQLiteDatabase.beginTransactionWithListener(SQLiteDatabase.java:706)
at net.sqlcipher.database.SQLiteDatabase.beginTransaction(SQLiteDatabase.java:658)
at com.pos.xwpos.db.DBFactory.saveroleRightGroup(DBFactory.java:4959)
at com.pos.xwpos.task.GetMerrightsetsTask.doInBackground(GetMerrightsetsTask.java:133)
at com.pos.xwpos.task.GetMerrightsetsTask.doInBackground(GetMerrightsetsTask.java:36)
at android.os.AsyncTask$2.call(AsyncTask.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)