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
vs1784
Posts: 6
Registered: ‎06-29-2011
My Device: Bold 9700
Accepted Solution

OS 6.0+ sqLite Multithreading and Synchronized

I am trying to create an application which has multiple threads running in background. In total there would be 5 threads including UI thread and all would be editing and reading database.

 

I have created a static final object to be used for synchronization purpose.

 

For each SQL statement i am enclosing it in

 

synchronized (GlobalVariables.lockObject) {
//// Create or Open Database
//// Create Statement
//// Prepare Statment & Execute
//// Close Database
//// lockObject.notify()

}

 

Theoritically i belive this should work in multithreading environment. However it doesnt. It works for UI thread but then it waits indefinately at prepare statement for background thread at random places in my code and doesnt move ahead until i take some action in UI thread which makes some database operation.

 

This works perfectly in OS 7.0 but not working in 6.0 simulator and devices.

 

Can someone help me here? I am really stuck at here since last 4 days.

 

Thank You

Please use plain text.
New Contributor
vs1784
Posts: 6
Registered: ‎06-29-2011
My Device: Bold 9700

Re: OS 6.0+ sqLite Multithreading and Synchronized

Some more information in regards to above posting.

 

When my thread goes into waiting mode it stucks at SQLite Pending Operation and doesnt move until i my app does any other database transaction in UI Thread.

 

I am creating and closing db connection for each database operation in UI and background threads.

 

I am not sure if this is the best way to handle multiple thread sqlite operation but so far there is no documentation available in BlackBerry or forums and few links i found in forum suggested the way i mentioned above.

Please use plain text.
New Contributor
vs1784
Posts: 6
Registered: ‎06-29-2011
My Device: Bold 9700

Re: OS 6.0+ sqLite Multithreading and Synchronized

I have found solution.

 

Apprantly in my case i had a UI element invalidating its parent element in paint method.

 

Thus UI was going into infinite loop and since in OS 6.0 UI methods takes higher precedence and thread is kept on wait until UI methods are completed it was stucked in thread.

 

Thanks to all who read this post and tried to help me out.

Please use plain text.