Use case of Multi thread | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Use case of Multi thread

Hi Theoretically i know that multi thread application is useful to have parallel processing to make application faster. I have all the use case where one part is completed then only we can process other. Can any one help me highlight use case of multi thread application? I am into application engineering development domain and would appreciate the use case around the same or similar domain. P.S. : Please don't provide use case of embedded as I have multiple friends who each time gives same example, but not able to co-relate with my domain. Many thanks in advance..!

21st May 2020, 3:43 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
3 Answers
+ 1
Any kind of more or less complex calculations (primarily in backends) which are - hopefully - implemented performant enough to underperforme the machine with a single instance &/ thread. More concrete? What about e.g. billing systems, creating invoice mails for millions of customers?
22nd May 2020, 12:32 AM
Sandra Meyer
Sandra Meyer - avatar
0
thanks a lot....! regarding the example you mentioned about billing system, do I need to have thread t1,t2 and so on in main function as and when user demands for bill? How to implement the same in a main function? This hint will help me understand how to code the same and observe advantage of thread.
22nd May 2020, 6:40 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
Usually you would use something like a JBoss or implement an additional load balancer to take care of this. For a single standalone program and learning it's sufficient to implement a small Runnable and start it n times via a loop. To keep a constant number of n threads you would need something like a queue, or for the first steps a simple counter, which is accessed by the instances of your Runnable. A thread knows when its job is done and can decrease the counter then, what would make e.g. a while x < 10 loop in main start another thread. Don't forget to add some sleep times!
22nd May 2020, 11:21 AM
Sandra Meyer
Sandra Meyer - avatar