Example usage for java.util.concurrent ThreadFactory newThread

List of usage examples for java.util.concurrent ThreadFactory newThread

Introduction

In this page you can find the example usage for java.util.concurrent ThreadFactory newThread.

Prototype

Thread newThread(Runnable r);

Source Link

Document

Constructs a new Thread .

Usage

From source file:org.apache.hadoop.hbase.regionserver.MemStoreFlusher.java

synchronized void start(UncaughtExceptionHandler eh) {
    ThreadFactory flusherThreadFactory = Threads
            .newDaemonThreadFactory(server.getServerName().toShortString() + "-MemStoreFlusher", eh);
    for (int i = 0; i < flushHandlers.length; i++) {
        flushHandlers[i] = new FlushHandler("MemStoreFlusher." + i);
        flusherThreadFactory.newThread(flushHandlers[i]);
        flushHandlers[i].start();//from ww  w  . j  a  v a  2s  . c o  m
    }
}

From source file:org.apache.http.HC4.impl.nio.client.CloseableHttpAsyncClientBase.java

public CloseableHttpAsyncClientBase(final NHttpClientConnectionManager connmgr,
        final ThreadFactory threadFactory, final NHttpClientEventHandler handler) {
    super();/* ww w.j  a  va 2 s .  c o  m*/
    this.connmgr = connmgr;
    if (threadFactory != null && handler != null) {
        this.reactorThread = threadFactory.newThread(new Runnable() {

            @Override
            public void run() {
                try {
                    final IOEventDispatch ioEventDispatch = new InternalIODispatch(handler);
                    connmgr.execute(ioEventDispatch);
                } catch (final Exception ex) {
                    log.error("I/O reactor terminated abnormally", ex);
                } finally {
                    status.set(Status.STOPPED);
                }
            }

        });
    } else {
        this.reactorThread = null;
    }
    this.status = new AtomicReference<Status>(Status.INACTIVE);
}

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//w  w w  .jav a 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  ww w .  j  av 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;
}

From source file:org.springframework.osgi.extender.internal.support.ExtenderConfiguration.java

private TaskExecutor createDefaultShutdownTaskExecutor() {
    ThreadPoolTaskScheduler taskExecutor = new ThreadPoolTaskScheduler() {
        private static final long serialVersionUID = 1L;

        protected ScheduledExecutorService createExecutor(int poolSize, final ThreadFactory threadFactory,
                RejectedExecutionHandler rejectedExecutionHandler) {

            ThreadFactory tf = new ThreadFactory() {
                public Thread newThread(Runnable r) {
                    Thread t = threadFactory.newThread(r);
                    t.setName("Spring DM context shutdown thread");
                    return t;
                }//from w  w w  . j  a v a2s  . c  o  m

            };

            return new ScheduledThreadPoolExecutor(poolSize, tf, rejectedExecutionHandler);
        }
    };
    taskExecutor.afterPropertiesSet();
    isShutdownTaskExecutorManagedInternally = true;
    return taskExecutor;
}