I am new to multithreading and wanted to know if I could offer the core working on the main thread to be used from the threadpool or does that happen automatically if I use an ExecutorService while calling invokeAll?
I came to this qestion because my performance tests showed a speedup of a maximum of about 2.7 when using 3 or 4 threads in the fixed thread pool.
But the Runtime says I have 4 available processors (due to hyperthreading on corei3) so I would like to get a speedup near 4.
Or does my OS need at least one core occupied?
MWE:
private void doParallel() {
List<Callable<Object>> jobs = new ArrayList<Callable<Object>>(threadCount);
for (int i = 0; i < threadCount; i++) {
jobs.add(new Callable<Object>() {
@Override
public Object call() {
// compute something heavy
return null;
}
});
}
// is it possible to pause the main thread here to make one
// additional core available for the threadPool?
threadPool.invokeAll(jobs); // TODO Exception
}