05-23-2012 04:21 AM
I am having an issue where I have two or more threads accessing the sqlite database on my BB app. Each of the threads require the ability to read and write to the db and occasionally I get an error stating the database is locked when more than one thread is writing to the database at the same time - this results in data missing in the database on the device.
I have tried many different approaches to fixing this but cannot seem to get it right.
Please can someone give me some assistance as to how I create a single access point to the database which can be utilised by all of the threads when write access is required and a type of queue is maintained for the requestes for writing to the database.
I would appreciate a small code sample if available.
Thanks in advance
05-23-2012 02:29 PM
I think the best approach is to hold a queue of Runnables and attend to them one by one (think of it as a thread pool with only one active thread).
Here is a link which contain an example for such a thread pool. Be advise that:
1. It's not originally for BB so you might have to do some modifications.
2. I haven't tested it so I don't know if it's bug free or not. At first glance, it seems legit.
Here is the link:
Hope that helps,