Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi Processing in JAVA

I have a Process in Java, tat takes 4 mins to complete. 10 such process lined up takes around 40 mins. If i Thread the processes like One thread for a process, all the 10 process would be running parallely, it takes around 20 mins to complete. Isn't it suppose to take 4 mins to complete since all the process are running in parallel?

like image 525
SriHarish Avatar asked Sep 27 '26 03:09

SriHarish


2 Answers

If all those threads are running on a single processor the operating system has to time slice and context switch. That overhead adds time.

There is no parallelism until you have multiple processors to split the work. Threads can't reduce the work on a single processor.

like image 157
duffymo Avatar answered Sep 28 '26 17:09

duffymo


Isn't it suppose to take 4 mins to complete since all the process are running in parallel?????

Only if you actually had 10 cores and the program is completely CPU-bound. Either your machine has only 2 cores, or the program is partially IO- or memory-bound. All of those are quite common.

like image 45
Michael Borgwardt Avatar answered Sep 28 '26 16:09

Michael Borgwardt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!