简体   繁体   English

安卓房间数据库被锁定

[英]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.当我使用第 3 方非线程安全的 sqlite 库时,我从生产中得到了“android.database.sqlite.SQLiteDatabaseLockedException”异常。 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.然后我将我的 orm 移动到完全线程安全的 Room 数据库。 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?那么,Room db 线程不是安全的吗?它不是像 Google 提到的那样解决了传统 sqlite 库的问题吗? Is there anybody who faces db locked error with Room?是否有人在使用 Room 时遇到数据库锁定错误?

Please, check https://stackoverflow.com/a/63849367/3256989 .请检查https://stackoverflow.com/a/63849367/3256989 In short words, try to use enableMultiInstanceInvalidation() during building RoomDatabase.简而言之,尝试在构建 RoomDatabase 期间使用enableMultiInstanceInvalidation()

Try setting Journal Mode to JournalMode.AUTOMATIC .尝试将 Journal Mode 设置为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 Android Room 数据库日志模式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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