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:com.rhythm.louie.jms.MessageUpdate.java

public synchronized void initialize() throws Exception {
    if (queue == null) {
        ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("louie-jms-%d").build();
        queue = Executors.newSingleThreadExecutor(threadFactory);
    } else if (queue.isShutdown()) {
        throw new Exception("Cannot initialize!  Already shutdown!");
    }//from  w  w w.j a  v a 2  s .  c  om
}

From source file:org.eclipse.che.api.vfs.impl.file.event.VfsEventService.java

VfsEventService() {
    final String threadName = getClass().getSimpleName().concat("Thread-%d");
    final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat(threadName).setDaemon(TRUE)
            .build();//  w w w  .  j a  va  2s  .  co m

    this.executor = newSingleThreadExecutor(threadFactory);
    this.running = new AtomicBoolean(FALSE);
}

From source file:co.paralleluniverse.galaxy.core.NodeOrderedThreadPoolExecutor.java

@ConstructorProperties({ "cluster", "corePoolSize", "maximumPoolSize", "keepAliveTime", "unit",
        "maxQueueSize" })
public NodeOrderedThreadPoolExecutor(Cluster cluster, int corePoolSize, int maximumPoolSize, long keepAliveTime,
        TimeUnit unit, int maxQueueSize) {
    super(corePoolSize, maximumPoolSize, keepAliveTime, unit, maxQueueSize,
            new ThreadFactoryBuilder().setDaemon(true).build());
    cluster.addNodeChangeListener(listener);
}

From source file:ch.vorburger.osgi.builder.internal.ExecutorServiceProvider.java

private static ThreadFactory newNamedThreadFactory(Logger logger, String poolName) {
    // as in https://github.com/opendaylight/infrautils/blob/master/common/util/src/main/java/org/opendaylight/infrautils/utils/concurrent/ThreadFactoryProvider.java
    return new ThreadFactoryBuilder().setNameFormat(poolName + "-%d")
            .setUncaughtExceptionHandler((thread, throwable) -> logger
                    .error("Thread terminated due to uncaught exception: {}", thread.getName(), throwable))
            .build();//from   www  .j av  a 2 s  .  c  o  m
}

From source file:co.paralleluniverse.fibers.jdbc.FiberDriver.java

@Suspendable
@Override//from www  .j  a v a2 s  .  co m
public FiberConnection connect(final String url, final Properties info) throws SQLException {
    final String dbURL = url.replaceFirst("fiber:", "");
    final int threadCount = Integer.parseInt(info.getProperty(THREADS_COUNT, "10"));
    info.remove(THREADS_COUNT);
    final ExecutorService es = Executors.newFixedThreadPool(threadCount,
            new ThreadFactoryBuilder().setNameFormat("jdbc-worker-%d").setDaemon(true).build());
    final Connection con = JDBCFiberAsync.exec(es, new CheckedCallable<Connection, SQLException>() {
        @Override
        public Connection call() throws SQLException {
            return DriverManager.getConnection(dbURL, info);
        }
    });
    return new FiberConnection(con, MoreExecutors.listeningDecorator(es));
}

From source file:at.ac.univie.isc.asio.d2rq.pool.PooledD2rqFactory.java

public static JenaFactory using(final D2rqConfigModel d2rq, final Jdbc jdbc, final Timeout timeout,
        final int size) {
    final D2rqModelAllocator allocator = new D2rqModelAllocator(d2rq, jdbc);
    // fail fast if d2rq config is corrupt - stormpot may endlessly try to allocate models otherwise
    allocator.newModel().close(); // this should throw if config is corrupt
    final Config<PooledModel> config = new Config<>()
            // D2rqModelAllocator performs validation checks on #reallocate()
            // set a short expiration period to enable frequent liveness checks
            .setAllocator(allocator).setExpiration(new TimeSpreadExpiration(15, 30, TimeUnit.SECONDS))
            .setPreciseLeakDetectionEnabled(true)
            .setThreadFactory(new ThreadFactoryBuilder().setNameFormat("d2rq-pool-%d").build()).setSize(size);
    final QueuePool<PooledModel> pool = new QueuePool<>(config);
    return new PooledD2rqFactory(pool, d2rq.getPrefixes(), timeout);
}

From source file:org.apache.kylin.metrics.lib.impl.BaseScheduledReporter.java

BaseScheduledReporter(String name) {
    this(Executors.newSingleThreadScheduledExecutor(
            new ThreadFactoryBuilder().setNameFormat("metrics-scheduler-" + name + "-%d").build()));
}

From source file:org.apache.druid.query.PrioritizedExecutorService.java

public static PrioritizedExecutorService create(Lifecycle lifecycle, DruidProcessingConfig config) {
    final PrioritizedExecutorService service = new PrioritizedExecutorService(
            new ThreadPoolExecutor(config.getNumThreads(), config.getNumThreads(), 0L, TimeUnit.MILLISECONDS,
                    new PriorityBlockingQueue<Runnable>(),
                    new ThreadFactoryBuilder().setDaemon(true).setNameFormat(config.getFormatString()).build()),
            config);//  w  ww  . jav a  2s  .c o  m

    lifecycle.addHandler(new Lifecycle.Handler() {
        @Override
        public void start() {
        }

        @Override
        public void stop() {
            service.shutdownNow();
        }
    });

    return service;
}

From source file:com.splicemachine.olap.MappedJobRegistry.java

public MappedJobRegistry(long tickTime, int numTicks, TimeUnit unit) {
    this.tickTime = unit.toMillis(tickTime);
    this.numTicks = numTicks;
    this.registry = new ConcurrentHashMap<>();
    this.registryCleaner = Executors.newSingleThreadScheduledExecutor(
            new ThreadFactoryBuilder().setDaemon(true).setNameFormat("jobRegistryCleaner").build());
    this.registryCleaner.scheduleWithFixedDelay(new Cleaner(), 1l, 10l, unit);
}

From source file:org.graylog2.inputs.transports.SyslogTcpTransport.java

private static Executor executorService(final String executorName, final String threadNameFormat,
        final MetricRegistry metricRegistry) {
    final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat(threadNameFormat).build();
    return new InstrumentedExecutorService(Executors.newCachedThreadPool(threadFactory), metricRegistry,
            name(SyslogTcpTransport.class, executorName, "executor-service"));
}