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

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

Introduction

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

Prototype

public ThreadFactoryBuilder() 

Source Link

Document

Creates a new ThreadFactory builder.

Usage

From source file:org.glowroot.agent.util.ThreadFactories.java

public static ThreadFactory create(String name) {
    final ThreadFactory backingThreadFactory = new ThreadFactoryBuilder().setDaemon(true).setNameFormat(name)
            .build();//  w  w w .  j a  v a  2  s .  co  m
    return new ThreadFactory() {
        @Override
        public Thread newThread(Runnable r) {
            Thread thread = backingThreadFactory.newThread(r);
            thread.setContextClassLoader(ThreadFactories.class.getClassLoader());
            return thread;
        }
    };
}

From source file:org.kurento.commons.ThreadFactoryCreator.java

public static ThreadFactory create(String name) {
    return new ThreadFactoryBuilder().setNameFormat(name + "-e" + numExecutor.incrementAndGet() + "-t%d")
            .build();/*from  ww  w .ja  v  a2 s. c  o m*/
}

From source file:cc.recommenders.utils.Executors.java

public static ThreadPoolExecutor coreThreadsTimoutExecutor(final int numberOfThreads, final int threadPriority,
        final String threadNamePrefix) {
    final ThreadFactory factory = new ThreadFactoryBuilder().setPriority(threadPriority)
            .setNameFormat(threadNamePrefix + "%d").setDaemon(true).build();
    final ThreadPoolExecutor pool = new ThreadPoolExecutor(numberOfThreads, numberOfThreads, 100L, MILLISECONDS,
            new LinkedBlockingQueue<Runnable>(), factory);

    pool.allowCoreThreadTimeOut(true);/*from  ww  w  . ja v  a2 s  . c  o m*/
    return pool;
}

From source file:com.shazam.fork.Utils.java

public static ExecutorService namedExecutor(int numberOfThreads, String nameFormat) {
    ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat(nameFormat).build();
    return newFixedThreadPool(numberOfThreads, namedThreadFactory);
}

From source file:eu.itesla_project.iidm.network.impl.util.MultiStateNetworkAwareExecutors.java

private static ThreadFactory threadFactory(String poolName) {
    return new ThreadFactoryBuilder().setNameFormat(poolName + "-%d").build();
}

From source file:io.atomix.utils.concurrent.Threads.java

/**
 * Returns a thread factory that produces threads named according to the
 * supplied name pattern.// w  w w .jav  a  2s  . c om
 *
 * @param pattern name pattern
 * @return thread factory
 */
public static ThreadFactory namedThreads(String pattern, Logger log) {
    return new ThreadFactoryBuilder().setNameFormat(pattern).setThreadFactory(new AtomixThreadFactory())
            .setUncaughtExceptionHandler((t, e) -> log.error("Uncaught exception on " + t.getName(), e))
            .build();
}

From source file:sg.atom.utils.execution.services.ExecutorServices.java

public static ExecutorService create(Lifecycle lifecycle, ExecutorServiceConfig config) {
    return manageLifecycle(lifecycle, Executors.newFixedThreadPool(config.getNumThreads(),
            new ThreadFactoryBuilder().setDaemon(true).setNameFormat(config.getFormatString()).build()));
}

From source file:co.paralleluniverse.fibers.dropwizard.FiberManagedDataSource.java

public static ManagedDataSource wrap(ManagedDataSource ds, int numThreads) {
    return wrap(ds, Executors.newFixedThreadPool(numThreads,
            new ThreadFactoryBuilder().setNameFormat("jdbc-worker-%d").setDaemon(true).build()));
}

From source file:com.metamx.druid.concurrent.Execs.java

public static ExecutorService singleThreaded(String nameFormat) {
    return Executors.newSingleThreadExecutor(
            new ThreadFactoryBuilder().setDaemon(true).setNameFormat(nameFormat).build());
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.util.MMXExecutors.java

public static ExecutorService getOrCreate(String name, int size) {
    ExecutorService service = executorMap.get(name);
    if (service == null) {
        ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat(name + "-%d").build();
        service = Executors.newFixedThreadPool(size, namedThreadFactory);
        ExecutorService service1 = executorMap.putIfAbsent(name, service);
        if (service1 != null) {
            service = service1;//w w w.  ja  v a 2 s.  c  o  m
        }
    }
    return service;
}