3

I have a content provider which is going out to some record sources in the cloud and doing queries, the results are added to a cursor reference that is passed into those classes

WebSearch1.addCursor(mContext, cursor, projection, filter);
WebSearch2.addCursor(mContext, cursor, projection, filter);

Works great, but it is asynchronous, would like to kick it off in a async task/thread to improve response times. I could create a cursor in for each of the sources, and then add them into a MergeCursor. Not a huge deal to do it that way, but just wondering if the cursor is thread safe to pass off to two different threads to add to the cursor synchronously.

Thanks,

Chrispix
  • 17,941
  • 20
  • 62
  • 70

1 Answers1

3

This interface provides random read-write access to the result set returned by a database query. Cursor implementations are not required to be synchronized so code using a Cursor from multiple threads should perform its own synchronization when using the Cursor.

L7ColWinters
  • 1,342
  • 1
  • 14
  • 31
  • 1
    There is only one implicit current-row pointer inside of a `Cursor`. Two different threads cannot be working on two different rows at the same time. While one can argue that with sufficiently coarse-grained synchronization, you can get around this, I'd argue that a `Cursor` is pretty much single-threaded in practice. – CommonsWare Feb 03 '12 at 21:58
  • 1
    Pretty much did an async task for each of the cursors and then used MergeCursor once they were all done. – Chrispix Feb 04 '12 at 04:26