I've been trying to figure out for hours on why my application database gets deadlocked.
I have an app that reads the database from activities and writes to the database from a service. Pretty straight-forward.
I have my database connection set up as an instance:
public static synchronized MuseoDatabase getInstance(Context context){
if(sInstance == null){
sInstance = new MuseoDatabase(context);
}
return sInstance;
}
The service
In my service I have a Runnable that periodically updates the database with a transaction. Sometimes even with large chunks (300+ entries) of data.
In the service I have the instance opened for writing
final SQLiteDatabase db = MuseoDatabase.getInstance(getApplicationContext()).getWritableDatabase();
The service works okay. It updates the database pretty nicely and all is good there.
The problematic activity
Now I have an activity that accepts both RFID and numeric code input and they both are validated through one validateCode() method.
For this I open the database instance in read mode
final SQLiteDatabase db = MuseoDatabase.getInstance(getApplicationContext()).getReadableDatabase();
Now for the funny part
As I said above, both the RFID uuid and numeric code are validated through the same method because the value is saved in the same SQLite table.
When I validate the code, all is ok. It correctly checks the database for the code and if it is valid etc. But now if I were to read the RFID: deadlock and the error:
The connection pool for database has been unable to grant a connection to thread 602 (Binder_2) with flags 0x1
It even causes the RFID reader of the app to fail (no more rfid cards are detected). The numeric code has no issues but when using the rfid, it just plain fails although they both sue the same method.
After the failrue due to the rfid card, numeric codes still continue to function which makes it even more weird.
Where could have I gone wrong?
Aucun commentaire:
Enregistrer un commentaire