Example usage for java.util.concurrent Executors newFixedThreadPool

List of usage examples for java.util.concurrent Executors newFixedThreadPool

Introduction

In this page you can find the example usage for java.util.concurrent Executors newFixedThreadPool.

Prototype

public static ExecutorService newFixedThreadPool(int nThreads, ThreadFactory threadFactory) 

Source Link

Document

Creates a thread pool that reuses a fixed number of threads operating off a shared unbounded queue, using the provided ThreadFactory to create new threads when needed.

Usage

From source file:net.sourceforge.subsonic.service.PodcastService.java

public PodcastService() {
    ThreadFactory threadFactory = new ThreadFactory() {
        public Thread newThread(Runnable r) {
            Thread t = Executors.defaultThreadFactory().newThread(r);
            t.setDaemon(true);/* ww w.j a  v  a2 s  .c om*/
            return t;
        }
    };
    refreshExecutor = Executors.newFixedThreadPool(5, threadFactory);
    downloadExecutor = Executors.newFixedThreadPool(3, threadFactory);
    scheduledExecutor = Executors.newSingleThreadScheduledExecutor(threadFactory);
}

From source file:koper.client.DefaultConsumerLauncher.java

private void startMessageDispatcher(int size) {

    //Start dispatcher thread pool
    ExecutorService dispatcherPool = Executors.newFixedThreadPool(size,
            new NamedThreadFactory(MessageDispatcherThread.class.getSimpleName()));
    try {//from w w w  .  j  a v  a 2 s.co  m
        for (int i = 0; i < size; i++) {
            MessageDispatcher messageDispatcher = this.messageDispatcherClass.newInstance();
            MessageDispatcherThread messageDispatcherThread = new MessageDispatcherThread(messageDispatcher,
                    this.messageCenter, this.listenerRegistry);
            dispatcherPool.execute(messageDispatcherThread);
        }
    } catch (InstantiationException | IllegalAccessException e) {
        log.error("???,  [{}]", ExceptionUtils.getFullStackTrace(e));
        throw new RuntimeException(e);
    }
}

From source file:com.linkedin.pinot.core.query.scheduler.resources.ResourceManager.java

/**
 * @param config configuration for initializing resource manager
 *///from  ww  w . j  av a  2s  .  c o m
public ResourceManager(Configuration config) {
    numQueryRunnerThreads = config.getInt(QUERY_RUNNER_CONFIG_KEY, DEFAULT_QUERY_RUNNER_THREADS);
    numQueryWorkerThreads = config.getInt(QUERY_WORKER_CONFIG_KEY, DEFAULT_QUERY_WORKER_THREADS);

    LOGGER.info("Initializing with {} query runner threads and {} worker threads", numQueryRunnerThreads,
            numQueryWorkerThreads);
    // pqr -> pinot query runner (to give short names)
    ThreadFactory queryRunnerFactory = new ThreadFactoryBuilder().setDaemon(false)
            .setPriority(QUERY_RUNNER_THREAD_PRIORITY).setNameFormat("pqr-%d").build();
    queryRunners = MoreExecutors
            .listeningDecorator(Executors.newFixedThreadPool(numQueryRunnerThreads, queryRunnerFactory));

    // pqw -> pinot query workers
    ThreadFactory queryWorkersFactory = new ThreadFactoryBuilder().setDaemon(false)
            .setPriority(Thread.NORM_PRIORITY).setNameFormat("pqw-%d").build();
    queryWorkers = MoreExecutors
            .listeningDecorator(Executors.newFixedThreadPool(numQueryWorkerThreads, queryWorkersFactory));
}