Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the most efficient way to create additional threads from a thread?

Question

What is the most efficient way to create additional threads from a thread?

Context

I am redesigning an application to be more efficient. One of the largest improvements will be running concurrent operations; however I am new to concurrent programming. The scenario I am looking to improve is as follows:

We have multiple marketplaces to import orders from and then upload to our ERP system. Each marketplace has multiple record types to import. Currently this is done like MP->RT->RT->RT->RT where the marketplace(MP) is invoked, and than subsequent recordtypes(RT) are added.

What I want to accomplish is a flow like:

MP 
  |-> RT
  |-> RT
  |-> RT
  |-> RT
MP
  |-> RT
  |-> RT
  ...

where multiple marketplaces are invoked, and then multiple record types are added concurrently.

I am currently using an executor service that controls MP tasks, but I want to know the best way to handle RT tasks.

like image 611
Robert H Avatar asked May 27 '13 14:05

Robert H


1 Answers

Can't you submit each RT task in a ThreadPool (MT) and let them run separately?

You can have multiple Executors (ThreadPool is one amongs other, choose the one that suits your needs best) or just one, and every RT task can be submited inside them.

like image 128
Djon Avatar answered Oct 12 '22 13:10

Djon