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 7493817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:11:37+00:00 2026-05-29T17:11:37+00:00

I have never used threads–never thought my code would benefit. However, I think threading

  • 0

I have never used threads–never thought my code would benefit. However, I think threading might improve performance of the following pseudo code:

Loop through table of records containing security symbol field and a quote field
    Load a web page (containing a security quote for a symbol) into a string variable
    Parse the string for the quote
    Save the quote in the table
    Get next record
end loop

Loading each web page takes the most time. Parsing for the quote is quite fast. I guess I could take, say, half the records for one thread and work the other half in a second thread.

  • 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-29T17:11:38+00:00Added an answer on May 29, 2026 at 5:11 pm

    In OmniThreadLibrary it is very simple to solve this problem with a multistage pipeline – first stage runs on multiple tasks and downloads web pages and second stage runs in one instance and stores data into the database. I have written a blog post documenting this solution some time ago.

    The solution can be summed up with the following code (you would have to fill in some places in HttpGet and Inserter methods).

    uses
      OtlCommon,
      OtlCollections,
      OtlParallel;
    
    function HttpGet(url: string; var page: string): boolean;
    begin
      // retrieve page contents from the url; return False if page is not accessible
    end;
    
    procedure Retriever(const input: TOmniValue; var output: TOmniValue);
    var
      pageContents: string;
    begin
      if HttpGet(input.AsString, pageContents) then
        output := TPage.Create(input.AsString, pageContents);
    end;
    
    procedure Inserter(const input, output: IOmniBlockingCollection);
    var
      page   : TOmniValue;
      pageObj: TPage;
    begin
      // connect to database
      for page in input do begin
        pageObj := TPage(page.AsObject);
        // insert pageObj into database
        FreeAndNil(pageObj);
      end;
      // close database connection
    end;
    
    procedure ParallelWebRetriever;
    var
      pipeline: IOmniPipeline;
      s       : string;
      urlList : TStringList;
    begin
      // set up pipeline
      pipeline := Parallel.Pipeline
        .Stage(Retriever).NumTasks(Environment.Process.Affinity.Count * 2)
        .Stage(Inserter)
        .Run;
      // insert URLs to be retrieved
      for s in urlList do
        pipeline.Input.Add(s);
      pipeline.Input.CompleteAdding;
      // wait for pipeline to complete
      pipeline.WaitFor(INFINITE);
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have never used octal numbers in my code nor come across any code
I've never used the Global Temporary Tables however I have some questions how they
I have used automation to insert values into a cell, however I have never
Firstly, I've never used threads, but have found lots of examples on the internet
I've never really used threading before in C# where I need to have two
i have never used LINQ in any of my projects , i have always
I have never used virtualization, and am trying to get up to speed. My
I have never used Perl, but I am really impressed by the ack ,
I have never used DBIx::Class until today, so I'm completely new at it. I'm
I am new ASP.NET and I have never used a GridView or DataGrid, but

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.