All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.instaclustr.threading.Executors Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package com.instaclustr.threading;

import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;

public abstract class Executors {

    public static final Integer DEFAULT_CONCURRENT_CONNECTIONS = 10;

    public static final class FixedTasksExecutorSupplier extends ExecutorServiceSupplier {

        @Override
        public ListeningExecutorService get(final Integer concurrentTasks) {
            if (concurrentTasks != null) {
                return MoreExecutors.listeningDecorator(java.util.concurrent.Executors.newFixedThreadPool(concurrentTasks));
            } else {
                return MoreExecutors.listeningDecorator(java.util.concurrent.Executors.newFixedThreadPool(DEFAULT_CONCURRENT_CONNECTIONS));
            }
        }
    }

    public static abstract class ExecutorServiceSupplier {

        public ListeningExecutorService get() {
            return get(DEFAULT_CONCURRENT_CONNECTIONS);
        }

        public abstract ListeningExecutorService get(final Integer concurrentTasks);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy