简体   繁体   中英

android room database locked

I had been getting " android.database.sqlite.SQLiteDatabaseLockedException" exception from production when I had been using 3rd party non-thread safe sqlite libraries. I checked all the threads and connection closing, I made all instances singleton but I wasn't able to solve the problem (I haven't even reproduce case myself). Then I moved my orm to Room database which is completely thread safe. But I'm still getting the exactly same error from production. So isn't Room db thread safe and isn't it take care of concerns for conventional sqlite libraries as Google mentioned? Is there anybody who faces db locked error with Room?

Please, check https://stackoverflow.com/a/63849367/3256989 . In short words, try to use enableMultiInstanceInvalidation() during building RoomDatabase.

Try setting Journal Mode to JournalMode.AUTOMATIC . Worked fine for me.

Sample code from my project

INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
                        MyDatabase.class, "myDatabase")
                        .addMigrations(MIGRATION_1_2)
                        .addCallback(sRoomDatabaseCallback)
                        .setJournalMode(JournalMode.AUTOMATIC)
                        .build();

Android Room Database Journal Mode

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM