Suppose, I am having a program that takes 1 minute to perform some calculations and having such 1000 transactions to calculate. What are the best ways to get this job done in 20 minutes? Do I have to spin 50 threads? Or are there any better ways?
Be careful with your assumption that mulithreading will make your
operations complete sooner. Its overhead may even slow them down
since the same number of calculations must be done by the same
CPU. Have you exhausted your search for better solution algorithms?
Jim ... ...
BEE MBA PMP SCJP-6
Joined: Jun 14, 2010
Kind of, currently it is handled by multi-process application but facing time limitations as number of transactions are increased.
First, you need to apply common sense to the problem. Threads doesn't increase the amount of resources that you have, it just makes it possible to use it. For example, if your computer has four cores, and one thread will use one core at 100 percent, then the theoretical maximum is four times faster. And if one thread is barely using any CPU, you need to look into why -- for example, if it is IO bound on the harddisk, then increasing the number of threads just means more threads waiting for the harddisk.
So... if you want to use many threads, you need to also make sure that you have the resources to support such a program. If you don't have the CPU cycles, or the IO capacity, or the network capacity, etc., adding threads won't do anything -- except add another level of complexity.