Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
GaryGoetsch
Posts: 3
Registered: ‎05-23-2012
My Device: 9860
My Carrier: MTN SA

Multi thread access to sqlite

Hi there

 

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

Gary

Please use plain text.
Developer
rabiray
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold
My Carrier: Vodafone

Re: Multi thread access to sqlite

Please use plain text.
Developer
maadani
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: Multi thread access to sqlite

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:

http://www.nloko.ca/?p=300

 

Hope that helps,

 

E.

Please use plain text.
New Contributor
GaryGoetsch
Posts: 3
Registered: ‎05-23-2012
My Device: 9860
My Carrier: MTN SA

Re: Multi thread access to sqlite

Hi rabiray

 

Thanks for the link, I will read through the doc and see what I get out of it

Please use plain text.
New Contributor
GaryGoetsch
Posts: 3
Registered: ‎05-23-2012
My Device: 9860
My Carrier: MTN SA

Re: Multi thread access to sqlite

Hi maadani

Thanks! I will take a look at the link and see if it sheds some light
Please use plain text.