If the number of records is relatively small, say, 50 or less, you can simply start a separate thread for each record and let them all work in parallel, for example:
begin thread Load a web page for symbol into a string variable Parse the string for the quote Save the quote in the table end thread
.
Loop through table of records Launch a thread for current security symbol Get next record end loop
If you have more records to process, consider using a thread pool so you can process records in smaller batches, for example:
Create X threads Put threads in a list Loop through table of records Wait until a thread in pool is idle Get idle thread from pool Assign current security symbol to thread Signal thread Get next record end loop Wait for all threads to be idle Terminate threads
.
begin thread Loop until terminated Mark idle Wait for signal If not Terminated Load a web page for current symbol into a string variable Parse the string for the quote Save the quote in the table end if end loop end thread
There are many different ways to implement the above, so I left it in pseudo-code. Take a look at the VCL TThread
, TList
and TEvent
or the Win32 API function QueueUserWorkerItem()
or any number of third-party thread libraries.
source share