The forum will be down for scheduled maintenance on Saturday, March 4 beginning at 10am EST. Actual downtime is unknown but may be several hours.

Hi Guys, I am developing an IPad application with Ultralite DB as Client DB. App is having a functionality of Read/Write data in local DB and Sync back to server.
Requirement:- User should be able to use normal UI functionality while Sync is running.
Approach:- I am using 2 separate connection object syncConn for Synchronization and connection for normal UI read/write functionality. I am running Sync in a background thread to keep the main thread free.
Problem Description:- When Sync is running in background and i click on UI, both Sync and UI are getting hanged. I am not getting any update from Sync and UI is not going where it should go.
I checked for Concurrent Connection behavior in documentation here. It say if Local operation try to change the data which sync is trying to change it will failes the Sync. But in my case (for now) i am just trying to Read some data out of DB when clicking on UI.

asked 11 Jun '12, 03:56

Gandalf's gravatar image

accept rate: 50%

"not getting any update from Sync": do you mean the sync observer callback function is no longer called? What do you normally do in the callback function?

(11 Jun '12, 18:33) Tim McClements

Yes i am referring to sync observer callback function here.And in that callback method i am printing only the sync status messages through NSLog statement.This method is no longer called as i don't see any NSlogs after clicking on UI.

(12 Jun '12, 01:29) Gandalf

Some info and suggestions to start...

For the connections, your approach sounds good. You need a separate connection for each different thread.

Normally UL serializes requests/calls - if you, say, execute two different statements (on two separate threads) at the same time, one call will run to completion while the other call blocks, and then the second call will run. Normally requests are short and you wouldn't notice the serialization.

For synchronization, since it's a long-running request, UL allows other requests to run concurrently. Here it is possible to notice a delay in a concurrent request because the request may have to block until the sync call is in a position to release its lock/mutex. (The sync call will continue with network I/O in the meantime, but when that's complete it will in turn block until the other request is done.)

Given all this, for UL itself, it should not be possible to hang the sync by making another request. Short delays are possible though. It may be best to perform all UL calls asynchronously to make sure the UI thread is never blocked and the app remains responsive.

For running background/asynchronous tasks on iOS, Apple suggests using NSOperations and queues. These simplify some of the common problems with threaded programming, and should lead to easier and more reliable programs. They are worth looking into if you are not using them already. The general idea would be that each database operation gets an associated NSOperation object which goes off and does the work and gathers the results - then the UI thread receives and uses the results when done.

permanent link

answered 11 Jun '12, 18:30

Tim%20McClements's gravatar image

Tim McClements
accept rate: 34%

Hi Tim, Thanks for all those suggestions. Just to update that i am already taking all these input into use. My UI related DB calls are on separate threads so as the sync call.
<Here it is possible to notice a delay in a concurrent request because the request may have to block until the sync call is in a position to release its lock/mutex.>
I completely agree with this point, but my app hasn't responded at all though i have been waiting for few minutes.
P.S. - The whole sync will take less than 40 seconds to complete.

(12 Jun '12, 01:39) Gandalf
Replies hidden

Without more detailed knowledge of your app it is hard to know what is causing the hang. Have you tried debugging the app? Once it hangs you should be able to use the debugger to find where the threads are all blocked (their call stacks). This may give you an idea about what is going wrong.

(12 Jun '12, 16:34) Tim McClements

My app is sort of form filling application for medical usage.
Yes i am constantly working on the various possible scenario which can cause it in my opinion. One weird thing i noticed last night when i run the app with breakpoints it worked just fine(Sync-UI concurrently) and when i removed them it again hangs.
In my opinion loading my apps UI is creating the problem as it load numerous views in single shot.
Meanwhile any idead would be appreciable. Will post back if i broke it.

(13 Jun '12, 03:10) Gandalf
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 11 Jun '12, 03:56

question was seen: 1,210 times

last updated: 13 Jun '12, 03:10