I'm using the Room persistence library on Android. Currently, I have some extra synchronization code each time I access the database. I want to know if this code is necessary.
I currently access the database as a singleton. This is how I am currently inserting objects into the DB:
// Insert values into DB
final AppDatabase db = AppDatabase.get(this);
AsyncTask.execute(new Runnable() {
@Override
public void run() {
synchronized (db) {
for (WorkOrder wo : workOrderList) {
db.workOrderDao().insertAll(wo);
}
}
}
});
Do I need to have the insertion code in a synchronized block?