/** * Creates {@link PredictableExecutor} instance. * * @param buckets number of buckets or 0 to match available processors * @param threadFactory {@link ThreadFactory} to use to create threads */ public PredictableExecutor(int buckets, ThreadFactory threadFactory) { checkArgument(buckets >= 0, "number of buckets must be non zero"); checkNotNull(threadFactory); if (buckets == 0) { buckets = Runtime.getRuntime().availableProcessors(); } this.backends = new ArrayList<>(buckets); for (int i = 0; i < buckets; ++i) { this.backends.add(backendExecutorService(threadFactory)); } }