Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 494523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:30:16+00:00 2026-05-13T05:30:16+00:00

I have an application that pulls data from the web, parses them, and compiles

  • 0

I have an application that pulls data from the web, parses them, and compiles the results in a search interface. Since the data are not co-dependant, it made sense to multi-thread the application to execute multiple fetches and parses simultaneously. I use NSInvocationOperation on a search and parse object I have written to execute this function.

In the controller object I have the following method:

-(void) searchAndParseAsynchronously { 
 NSPort *serverPort = [NSMachPort port];
 NSConnection *serverConnection = [NSConnection connectionWithReceivePort:serverPort sendPort:serverPort];
 [serverConnection setRootObject:self];
 for (NSURL *urlToProcess in self.urlsToFetch)
 {
  BaseSearchParser *searcherForURL = [BaseSearchParser newSearchParserWithParameters:self.searchParams];
  searcherForURL.urlToDocument = urlToDocument;

  SearchThreader *searchThreader = [SearchThreader new];
  searchThreader.threadConnection = comConnection;
  searchThreader.targetSchema = searcherForURL; 
  NSInvocationOperation *threaderOperation = [[NSInvocationOperation alloc] initWithTarget:searchThreader 
                                                                                        selector:@selector(executeSearchParse) 
                                                                                          object:nil];
  [self.operationQueue addOperation:threaderOperation];
 }
}

The application relies on Core Data, which I’ve gathered is mostly thread unsafe. I have a different NSManagedObjectContext for each search/parse operation (and one for the controller), and only pass the NSManagedObjectId between operations or proxy objects.

The operations communicate the completed parse results back to their controller via an NSConnection object. The controller constructs the NSConnection using an NSMachPort object, sets itself as the root object, and gives the same NSConnection object to each of the targets of the NSInvocationOperations. The controller then enqueues the NSInvocationOperation for execution in its own NSOperationQueue.

In the search threader object I have the following method:

-(void) executeSearchAndParse
{ 
 id parentServer = [threadConnection rootProxy];
 [parentServer setProtocolForProxy:@protocol(SearchParseProtocol)];

 NSArray *importResults = [targetSchema generatedDataSetIds];

 [parentServer schemaFinished:targetSchema];
 [parentServer addSearchResults:importResults];
}

I believe I have followed the Apple example of generic inter-thread communication given here.

I have to say that most of the time, this works beautifully: The notifications from the NSConnection rootProxy are posted to the run loop in the main thread as expected and wait for pickup until the controller object is ready. However, in some of my test cases it causes Core Data to grind to a screeching halt because sometimes the messages make it to the controller object in the same thread as the NSInvocationOperation object which is calling the rootProxy object.

I’ve placed a debugger point in the controller on the message which is sent when the search/parse operation is complete, and sure enough, sometimes (just sometimes) the executing thread is not the main one. Does anyone have an idea as to why this might occur? Or, is there a simpler way to construct inter-thread asynchronous communication? OR is my approach for Core Data totally off-kilter?

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:30:16+00:00Added an answer on May 13, 2026 at 5:30 am

    I don’t see anything wrong with your approach and have used NSConnection in similar manner before. The only I thing I see is that I just used NSPort instead of using NSMachPort explicitly.

    Or, is there a simpler way to construct inter-thread asynchronous communication?

    I don’t think Apple is promoting ditributed objects for inter-thread communication anymore. IIRC this guess is mostly based on documentation that I have seen mentioned which really promotes DOs for inter-thread communication but which since have been removed or edited.

    I also think that the thread-related performSelector: methods on NSObject are much easier to use:

    - (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait
    - (void)performSelector:(SEL)aSelector onThread:(NSThread *)thr withObject:(id)arg waitUntilDone:(BOOL)wait
    

    (while the second one is only available from 10.5 on).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an n-tier web application that pulls data from SQL Server. Our Data
I have an application that pulls data from several web services. The application is
I have an iPad application that pulls in all of its data from an
Scenario: I have an application that pulls data from a SQL database as well
We have an in-house application that pulls some data from some of Amazon's pages
I have an application that pulls names from the active directory for the domain
I have an application that uses Microsoft.Office.Interop.Excel to pull data from an Excel workbook.
I'm working on an AJAX application that pulls data from a live website, I
Im working with a flex application that pulls data from a java class file
I do not want Auditing or History tracking. I have an application that pulls

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.