Skip to content

Commit

Permalink
Use fixed thread pool
Browse files Browse the repository at this point in the history
There was no reason for using a cached thread pool. The number of tasks
(partion solvers, partCount) is fixed. They all need to be executed in
parallel to prevent partition starving, therefore the number of threads
needed is exactly same as parrtCount. No additional threads are needed.
  • Loading branch information
yurloc authored and ge0ffrey committed Oct 16, 2017
1 parent 1f3988e commit 041b344
Showing 1 changed file with 3 additions and 6 deletions.
Expand Up @@ -20,8 +20,8 @@
import java.util.List;
import java.util.ListIterator;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -174,11 +174,8 @@ public void solve(DefaultSolverScope<Solution_> solverScope) {
}

private ExecutorService createThreadPoolExecutor(int partCount) {
// Based on Executors.newCachedThreadPool(...)
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
60L, TimeUnit.SECONDS,
new SynchronousQueue<>(),
threadFactory);
ThreadPoolExecutor threadPoolExecutor
= (ThreadPoolExecutor) Executors.newFixedThreadPool(partCount, threadFactory);

if (threadPoolExecutor.getMaximumPoolSize() < partCount) {
throw new IllegalStateException(
Expand Down

0 comments on commit 041b344

Please sign in to comment.