For a typical computing-related application, a good rule is to use as many threads as you have hardware cores (or hyper-threads). Using more threads than cores will not make your application run faster. Instead, it will cause your application to use more memory than necessary. Each thread usually has a stack of 0.5 to 1 MB ... depending on your hardware and version of Java. If you create too many threads, additional memory usage will lead to a significant performance hit; i.e. more threads => slow program!
Another thing to keep in mind is that Java threads are very expensive to build on a typical JVM. Therefore, if a thread does not work enough (in its life), there is a risk that you spend more time creating threads than you get using several cores in the calculation.
Finally, you may find that the work does not spread evenly across all threads, depending on your minmax algorithm ... and the state of the game.
If I tried to implement this, I would start by implementing as a single-threaded application, and then:
- compare it to find out how long it will take to calculate more with a batch run,
- profile to get rid of any bottlenecks
- repeat the test to see if it is enough already.
If and only if he needs to go faster, I would then study the code and (if necessary) add some monitoring to see how to break the calculation into large enough pieces that will be executed in parallel.
Finally, I would use these results to develop and implement a multi-threaded version.
I would also look at alternatives ... for example using Java 7 fork / join instead of threads.
To answer your direct questions:
Is it efficient to use 25 threads?
Probably not. This would be effective if you had so many cores (unlikely!). And even then you will only get good acceleration from using a large number of threads, if you get more by running parallel operations than you lose because of the overhead associated with the stream. (In other words, it depends on how efficiently you use these threads.)
What does using 25 threads mean?
I assume that you mean that you created and started 25 threads, either explicitly or using some existing thread pool implementation.
But the bottom line is that if you have (say) 4 cores, then no more than 4 of these 25 threads can be executed at a time. The remaining threads will wait ...
Is it 25 times faster (most likely not)? What does it depend? Of course, on a computer, but how do you know how many threads can be used based on computer resources?
The main factor limiting performance is the number of cores. See above.
What happens if I use too many threads (I don’t think anything ...)?
Too many threads means that you are using more memory and that your application is running slower due to competition in memory bandwidth, competition for pages of physical memory, and additional garbage collection. These factors are application and platform dependent and difficult to quantify; that is, to predict or measure.
Depending on the nature of your application (that is, how you implement the algorithms), too many threads can lead to additional lock conflicts and thread context switching. It will also make your application slower.
It is impossible to predict what will happen without seeing your actual code. But the number of cores gives a theoretical upper bound on how much accelerates. If you have 4 cores, then you cannot get more than 4x speedup with multi-threaded access.