Example usage for com.google.common.util.concurrent ThreadFactoryBuilder build

List of usage examples for com.google.common.util.concurrent ThreadFactoryBuilder build

Introduction

In this page you can find the example usage for com.google.common.util.concurrent ThreadFactoryBuilder build.

Prototype

public ThreadFactory build() 

Source Link

Document

Returns a new thread factory using the options supplied during the building process.

Usage

From source file:flipkart.mongo.replicator.core.threadfactory.TaskThreadFactoryBuilder.java

public static ThreadFactory threadFactoryInstance(String threadNamePattern) {
    if (!threadFactoryPool.containsKey(threadNamePattern)) {
        synchronized (TaskThreadFactoryBuilder.class) {
            if (!threadFactoryPool.containsKey(threadNamePattern)) {
                ThreadFactoryBuilder threadFactoryBuilder = new ThreadFactoryBuilder()
                        .setNameFormat(threadNamePattern);
                threadFactoryPool.put(threadNamePattern, threadFactoryBuilder.build());
            }/*from   w  w w  .  j a  va2s  . c  o  m*/
        }
    }

    return threadFactoryPool.get(threadNamePattern);
}

From source file:com.google.firebase.internal.FirebaseScheduledExecutor.java

private static ThreadFactory decorateThreadFactory(ThreadFactory threadFactory, String name,
        Thread.UncaughtExceptionHandler handler) {
    checkArgument(!Strings.isNullOrEmpty(name));
    ThreadFactoryBuilder builder = new ThreadFactoryBuilder().setThreadFactory(threadFactory)
            .setNameFormat(name).setDaemon(true);
    if (handler != null) {
        builder.setUncaughtExceptionHandler(handler);
    }//  w  w  w.  j  a  v  a2s. c o m
    return builder.build();
}

From source file:org.apache.giraph.utils.ThreadUtils.java

/**
 * Creates new thread factory with specified thread name format.
 *
 * @param nameFormat defines naming format for threads created by
 *                   thread factory// w  w  w  .j a  v a  2  s .  c o m
 * @param exceptionHandler handles uncaught exceptions in all threads
 *                         produced created thread factory
 * @return new thread factory with specified thread name format and
 * exception handler.
 */
public static ThreadFactory createThreadFactory(String nameFormat,
        Thread.UncaughtExceptionHandler exceptionHandler) {
    ThreadFactoryBuilder builder = new ThreadFactoryBuilder().setNameFormat(nameFormat).setDaemon(true);
    if (exceptionHandler != null) {
        builder.setUncaughtExceptionHandler(exceptionHandler);
    }
    return builder.build();
}

From source file:io.druid.java.util.common.concurrent.Execs.java

public static ThreadFactory makeThreadFactory(@NotNull String nameFormat, @Nullable Integer priority) {
    final ThreadFactoryBuilder builder = new ThreadFactoryBuilder().setDaemon(true).setNameFormat(nameFormat);
    if (priority != null) {
        builder.setPriority(priority);/*  ww w .j a  v a2  s .c  o m*/
    }

    return builder.build();
}

From source file:org.apache.hadoop.hbase.thrift2.ThriftServer.java

private static ExecutorService createExecutor(int workerThreads, ThriftMetrics metrics) {
    CallQueue callQueue = new CallQueue(new LinkedBlockingQueue<Call>(), metrics);
    ThreadFactoryBuilder tfb = new ThreadFactoryBuilder();
    tfb.setDaemon(true);//from w ww  . ja  va  2  s .c  o  m
    tfb.setNameFormat("thrift2-worker-%d");
    return new ThreadPoolExecutor(workerThreads, workerThreads, Long.MAX_VALUE, TimeUnit.SECONDS, callQueue,
            tfb.build());
}

From source file:com.amazonaws.services.kinesis.multilang.MultiLangDaemonConfig.java

private static ExecutorService buildExecutorService(Properties properties) {
    int maxActiveThreads = getMaxActiveThreads(properties);
    ThreadFactoryBuilder builder = new ThreadFactoryBuilder().setNameFormat("multi-lang-daemon-%04d");
    LOG.debug(String.format("Value for %s property is %d", PROP_MAX_ACTIVE_THREADS, maxActiveThreads));
    if (maxActiveThreads <= 0) {
        LOG.info("Using a cached thread pool.");
        return new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS,
                new SynchronousQueue<Runnable>(), builder.build());
    } else {//  w  w w.ja v a  2  s  .  c o m
        LOG.info(String.format("Using a fixed thread pool with %d max active threads.", maxActiveThreads));
        return new ThreadPoolExecutor(maxActiveThreads, maxActiveThreads, 0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>(), builder.build());
    }
}

From source file:org.metaservice.kryo.run.KryoServer.java

public KryoServer() {
    ThreadFactoryBuilder threadFactoryBuilder = new ThreadFactoryBuilder();
    threadFactoryBuilder.setNameFormat("objectSpace-%d");
    objectSpaceExecutor = Executors.newFixedThreadPool(3, threadFactoryBuilder.build());
    threadFactoryBuilder.setNameFormat("mongoWriter-%d");
    mongoWriterExecutor = Executors.newFixedThreadPool(10, threadFactoryBuilder.build());
}

From source file:org.apache.omid.tso.LowWatermarkWriterImpl.java

@Inject
LowWatermarkWriterImpl(TSOServerConfig config, CommitTable commitTable, MetricsRegistry metrics)
        throws Exception {
    this.metrics = metrics;
    this.lowWatermarkWriter = commitTable.getWriter();
    // Low Watermark writer
    ThreadFactoryBuilder lwmThreadFactory = new ThreadFactoryBuilder().setNameFormat("lwm-writer-%d");
    this.lowWatermarkWriterExecutor = Executors.newSingleThreadExecutor(lwmThreadFactory.build());

    // Metrics config
    this.lwmWriteTimer = metrics.timer(name("tso", "lwmWriter", "latency"));
    LOG.info("PersistentProcessor initialized");
}

From source file:org.openecomp.sdc.be.components.distribution.engine.NotificationExecutorService.java

public ExecutorService createExcecutorService(
        DistributionNotificationTopicConfig distributionNotificationTopic) {

    Integer minThreadPoolSize = distributionNotificationTopic.getMinThreadPoolSize();
    if (minThreadPoolSize == null) {
        minThreadPoolSize = 0;/*from  w w  w . ja  v a 2 s .  co  m*/
    }

    Integer maxThreadPoolSize = distributionNotificationTopic.getMaxThreadPoolSize();
    if (maxThreadPoolSize == null) {
        maxThreadPoolSize = 10;
    }

    ThreadFactoryBuilder threadFactoryBuilder = new ThreadFactoryBuilder();
    threadFactoryBuilder.setNameFormat("distribution-notification-thread-%d");
    ThreadFactory threadFactory = threadFactoryBuilder.build();

    ExecutorService executorService = new ThreadPoolExecutor(minThreadPoolSize, maxThreadPoolSize, 60L,
            TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), threadFactory);

    return executorService;
}

From source file:org.apache.phoenix.schema.stats.StatisticsCollectionRunTracker.java

private StatisticsCollectionRunTracker(Configuration config) {
    int poolSize = config.getInt(QueryServices.STATS_SERVER_POOL_SIZE,
            QueryServicesOptions.DEFAULT_STATS_POOL_SIZE);
    ThreadFactoryBuilder builder = new ThreadFactoryBuilder().setDaemon(true)
            .setNameFormat("phoenix-update-statistics-%s");
    executor = Executors.newFixedThreadPool(poolSize, builder.build());
}