I’m starting to develop some multi-thread plataform to a project that allready exists (a non-multithreaded project) in Java and i need a performance GAIN, reducing the time of complex calculations that are all over the project.
I’ve being using Executors but i dont’t really know if it’s the best solution for performance gain compared to ThreadGroup or pure Runnable.
So, which one should be used?
You will only get a performance gain from thread pools if you reuse them for several computations (i.e. you start a pool with 10 threads and perform 10 tasks 100 times, instead of starting 10 threads every time 100 times). They still take an initial overhead to start up, you can’t escape this part. So here’s an example:
In this case, I only pay the overhead of starting 10 threads once, at the beginning.
Using pure threads:
In this case I pay the overhead of starting 10 threads twice, which is a bad use of threading. Of course, if you only need to execute those tasks once, there won’t be any performance difference, except that it’s easier to work with executors.
I don’t get what you mean by pure
Runnable(pure threads maybe?), since thread pools (executors) also work onRunnables.