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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With