I hava a java program, a section of it is compute intensive, like this
for i = 1 :512
COMPUTE INTENSIVE SECTION
end
I want to split it into multithread, make it faster when running.
COMPUTE INTENSIVE SECTION is not sequential-wise. It means running i=1 first or i=5 fist are the same…
Can anybody give me a grand guide about this. How to do it?
Thanks indeed!
Happy Thanksgiving!
Sounds like a thread pool would be good. Basically, you whip up a collection of N different threads, then request them in a loop. The request blocks until a thread is available.
With the Future’s you really don’t need to await termination. get()ing the result from a future will block until the corresponding thread is done (or canceled).