5

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.

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
Robert H
  • 11,520
  • 18
  • 68
  • 110
  • 2
    Why don't you use executor service for RT task also? – amicngh May 27 '13 at 14:24
  • @amicngh That's actually what I've been considering doing - I'm just unsure if creating multiple executor services is the most efficient way to do things. – Robert H May 27 '13 at 14:25
  • Each MP task handles bunch of RT tasks so better to create a ThreadPool and submit RT task to this pool . Each task will be done.. – amicngh May 27 '13 at 14:27

1 Answers1

6

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.

Djon
  • 2,230
  • 14
  • 19
  • 1
    Thanks - That aligns with how I've been thinking of the problem ( and based on the upvotes, how others see it as well ). – Robert H May 27 '13 at 14:29
  • I'm not sure I understood your question perflectly but this is indeed the first and most efficient solution that came to mind. – Djon May 27 '13 at 14:31