Example usage for java.util.concurrent ThreadPoolExecutor allowCoreThreadTimeOut

List of usage examples for java.util.concurrent ThreadPoolExecutor allowCoreThreadTimeOut

Introduction

In this page you can find the example usage for java.util.concurrent ThreadPoolExecutor allowCoreThreadTimeOut.

Prototype

boolean allowCoreThreadTimeOut

To view the source code for java.util.concurrent ThreadPoolExecutor allowCoreThreadTimeOut.

Click Source Link

Document

If false (default), core threads stay alive even when idle.

Usage

From source file:org.apache.lens.server.query.QueryExecutionServiceImpl.java

private void startEstimatePool() {
    int minPoolSize = conf.getInt(ESTIMATE_POOL_MIN_THREADS, DEFAULT_ESTIMATE_POOL_MIN_THREADS);
    int maxPoolSize = conf.getInt(ESTIMATE_POOL_MAX_THREADS, DEFAULT_ESTIMATE_POOL_MAX_THREADS);
    int keepAlive = conf.getInt(ESTIMATE_POOL_KEEP_ALIVE_MILLIS, DEFAULT_ESTIMATE_POOL_KEEP_ALIVE_MILLIS);

    final ThreadFactory defaultFactory = Executors.defaultThreadFactory();
    final AtomicInteger thId = new AtomicInteger();
    // We are creating our own thread factory, just so that we can override thread name for easy debugging
    ThreadFactory threadFactory = new ThreadFactory() {
        @Override// ww w  .ja va  2  s . c o m
        public Thread newThread(Runnable r) {
            Thread th = defaultFactory.newThread(r);
            th.setName("estimate-" + thId.incrementAndGet());
            return th;
        }
    };

    log.debug("starting estimate pool");

    ThreadPoolExecutor estimatePool = new ThreadPoolExecutor(minPoolSize, maxPoolSize, keepAlive,
            TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>(), threadFactory);
    estimatePool.allowCoreThreadTimeOut(false);
    estimatePool.prestartCoreThread();
    this.estimatePool = estimatePool;
}

From source file:org.apache.lens.server.query.QueryExecutionServiceImpl.java

private void startLauncherPool() {
    int minPoolSize = conf.getInt(LAUNCHER_POOL_MIN_THREADS, DEFAULT_LAUNCHER_POOL_MIN_THREADS);
    int maxPoolSize = conf.getInt(LAUNCHER_POOL_MAX_THREADS, DEFAULT_LAUNCHER_POOL_MAX_THREADS);
    int keepAlive = conf.getInt(LAUNCHER_POOL_KEEP_ALIVE_MILLIS, DEFAULT_LAUNCHER_POOL_KEEP_ALIVE_MILLIS);

    final ThreadFactory defaultFactory = Executors.defaultThreadFactory();
    final AtomicInteger thId = new AtomicInteger();
    // We are creating our own thread factory, just so that we can override thread name for easy debugging
    ThreadFactory threadFactory = new ThreadFactory() {
        @Override/*from w  w  w.  jav  a2 s.co m*/
        public Thread newThread(Runnable r) {
            Thread th = defaultFactory.newThread(r);
            th.setName("launcher-" + thId.incrementAndGet());
            return th;
        }
    };

    log.debug("starting query launcher pool");

    ThreadPoolExecutor launcherPool = new ThreadPoolExecutor(minPoolSize, maxPoolSize, keepAlive,
            TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>(), threadFactory);
    launcherPool.allowCoreThreadTimeOut(false);
    launcherPool.prestartCoreThread();
    this.queryLauncherPool = launcherPool;
}