SnappyDB icon indicating copy to clipboard operation
SnappyDB copied to clipboard

Issues with persisting objects over multiple network calls.

Open rajivenator opened this issue 10 years ago • 1 comments

Hi, I am a beginner on Android and I have been using SnappyDb for my project. I have a lot of network requests using retrofit. I am able to get the objects related to JSON passed over the network in my app. Now the issue is that upon receipt of the object i try to persist them, and they get persisted for few calls and later i start getting "com.snappydb.SnappydbException: Your database is still open, please close it" this error.

Is there a simpler way to check whether a db is open or not, and also if there are any such inbuilt methods to handle these situations.

rajivenator avatar Jun 12 '15 05:06 rajivenator

Hi @rajivenator since you're using Retrofit, I guess the real pb you're facing is concurrency. I doubt you're trying to write concurrently to your database which is not possible since the instance of SnappyDB is not Thread safe. What you need to do is synchronize your operations (by using intrinsic/private lock). you can also test if your db is open using dbInstance.isOpen()

Cheers,

nhachicha avatar Jun 13 '15 13:06 nhachicha