I am trying to build an implementation of the ExecutorService
, let\'s call it SequentialPooledExecutor
, with the following properties.
If you have thousands of keys which must be processed sequentially, but you don't have thousands of cores you can use a hashing strategy to distribute the work like this
ExecutorService[] es = // many single threaded executors
public Future submit(String key, Callable calls) {
int h = Math.abs(key.hashCode() % es.length);
return es[h].submit(calls);
}
In general you only need 2 * N threads to keep N cores busy, if your task is CPU bound, more than that just adds overhead.