Example usage for java.util.concurrent ThreadPoolExecutor setThreadFactory

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

Introduction

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

Prototype

public void setThreadFactory(ThreadFactory threadFactory) 

Source Link

Document

Sets the thread factory used to create new threads.

Usage

From source file:com.opengamma.language.context.DefaultGlobalContextEventHandler.java

public DefaultGlobalContextEventHandler() {
    final int cores = Runtime.getRuntime().availableProcessors();
    final ThreadPoolExecutor executor = new ThreadPoolExecutor(cores, cores, 60, TimeUnit.SECONDS,
            new LinkedBlockingQueue<Runnable>());
    executor.allowCoreThreadTimeOut(true);
    executor.setThreadFactory(new NamedThreadPoolFactory("S-Worker"));
    setSaturatingExecutor(executor);/* www .j av  a  2  s  . co m*/
}

From source file:co.paralleluniverse.galaxy.netty.AbstractTcpServer.java

private void configureThreadPool(String name, ThreadPoolExecutor executor) {
    executor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy());
    executor.setThreadFactory(
            new ThreadFactoryBuilder().setNameFormat(name + "-%d").setThreadFactory(new ThreadFactory() {
                @Override//from   w w  w  .  j av  a2s . c  om
                public Thread newThread(Runnable r) {
                    return new CommThread(r);
                }
            }).build());
    ThreadPoolExecutorMonitor.register(name, executor);
}

From source file:com.amazonaws.services.simpleworkflow.flow.worker.GenericActivityWorker.java

@Override
protected TaskPoller createPoller() {
    ThreadPoolExecutor tasksExecutor = new ThreadPoolExecutor(1, taskExecutorThreadPoolSize, 1,
            TimeUnit.MINUTES, new SynchronousQueue<Runnable>());
    tasksExecutor.setThreadFactory(
            new ExecutorThreadFactory(ACTIVITY_THREAD_NAME_PREFIX + " " + getTaskListToPoll() + " "));
    tasksExecutor.setRejectedExecutionHandler(new BlockCallerPolicy());
    return new ActivityTaskPoller(service, domain, getTaskListToPoll(), activityImplementationFactory,
            tasksExecutor);//ww  w. ja v a  2  s.c o  m
}

From source file:co.paralleluniverse.galaxy.netty.UDPComm.java

private void configureThreadPool(String name, ThreadPoolExecutor executor) {
    executor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy());
    executor.setThreadFactory(new ThreadFactoryBuilder().setNameFormat(name + "-%d").setDaemon(true)
            .setThreadFactory(new ThreadFactory() {
                @Override// w  w w .  ja va2 s  .c  om
                public Thread newThread(Runnable r) {
                    return new CommThread(r);
                }
            }).build());
    ThreadPoolExecutorMonitor.register(name, executor);
}

From source file:org.apache.hadoop.yarn.server.resourcemanager.security.DelegationTokenRenewer.java

protected ThreadPoolExecutor createNewThreadPoolService(Configuration conf) {
    int nThreads = conf.getInt(YarnConfiguration.RM_DELEGATION_TOKEN_RENEWER_THREAD_COUNT,
            YarnConfiguration.DEFAULT_RM_DELEGATION_TOKEN_RENEWER_THREAD_COUNT);

    ThreadFactory tf = new ThreadFactoryBuilder().setNameFormat("DelegationTokenRenewer #%d").build();
    ThreadPoolExecutor pool = new ThreadPoolExecutor(nThreads, nThreads, 3L, TimeUnit.SECONDS,
            new LinkedBlockingQueue<Runnable>());
    pool.setThreadFactory(tf);
    pool.allowCoreThreadTimeOut(true);/*from   w w  w  .  j a  v  a  2s .c om*/
    return pool;
}

From source file:org.mule.config.pool.DefaultThreadPoolFactory.java

protected void configureThreadFactory(String name, ThreadingProfile tp, ThreadPoolExecutor pool) {
    // use a custom ThreadFactory if one has been configured
    if (tp.getThreadFactory() != null) {
        pool.setThreadFactory(tp.getThreadFactory());
    } else {//w w  w. ja va2  s. com
        // ..else create a "NamedThreadFactory" if a proper name was passed in
        if (StringUtils.isNotBlank(name)) {
            // Threads must use the MuleApplicationClassLoader related to MuleContext or the
            // thread context class loader in case of embedding mule.
            pool.setThreadFactory(new NamedThreadFactory(name, Thread.currentThread().getContextClassLoader()));
        } else {
            // let ThreadPoolExecutor create a default ThreadFactory;
            // see Executors.defaultThreadFactory()
        }
    }
}