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.continuuity.weave.common.Threads.java

/**
 * Handy method to create {@link ThreadFactory} that creates daemon threads with the given name format.
 *
 * @param nameFormat Name format for the thread names
 * @return A {@link ThreadFactory}./*from  ww w .  j a  v  a  2s .co m*/
 * @see ThreadFactoryBuilder
 */
public static ThreadFactory createDaemonThreadFactory(String nameFormat) {
    return new ThreadFactoryBuilder().setDaemon(true).setNameFormat(nameFormat).build();
}

From source file:org.robotninjas.riemann.client.Clients.java

private static ExecutorService getExecutorService() {
    return newCachedThreadPool(
            new ThreadFactoryBuilder().setDaemon(true).setNameFormat("Riemann RiemannClient Thread").build());
}

From source file:tachyon.util.ThreadFactoryUtils.java

/**
 * Creates a {@link java.util.concurrent.ThreadFactory} that spawns off threads.
 *
 * @param nameFormat name pattern for each thread. should contain '%d' to distinguish between
 *                   threads.//www  . j  a  v  a  2s  .c  om
 * @param isDaemon if true, the {@link java.util.concurrent.ThreadFactory} will create
 *                 daemon threads.
 */
public static ThreadFactory build(final String nameFormat, boolean isDaemon) {
    return new ThreadFactoryBuilder().setDaemon(isDaemon).setNameFormat(nameFormat).build();
}

From source file:org.sonar.server.plugins.edition.EditionInstallerExecutor.java

private static ExecutorService createExecutor() {
    ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true)
            .setNameFormat("edition-installation-%d").build();
    return Executors.newSingleThreadExecutor(threadFactory);
}

From source file:cn.cdwx.jpa.utils.Threads.java

/**
 * ThreadFactory???"pool-x-thread-y"//from  w w w  .  jav a2  s  . c  o  m
 * threaddump ?"mythread-%d"
 */
public static ThreadFactory buildJobFactory(String nameFormat) {
    return new ThreadFactoryBuilder().setNameFormat(nameFormat).build();
}

From source file:com.github.jeluard.guayaba.util.concurrent.ThreadFactoryBuilders.java

/**
 * @param pattern//from w w  w  .  ja  v  a  2 s . c o  m
 * @param logger
 * @return {@link ThreadFactoryBuilder} producing daemon thread and relying on {@link UncaughtExceptionHandlers#defaultHandler(java.util.logging.Logger)}
 */
public static ThreadFactoryBuilder safeBuilder(final String pattern, final Logger logger) {
    Preconditions.checkNotNull(pattern, "null pattern");
    Preconditions.checkNotNull(logger, "null logger");

    return new ThreadFactoryBuilder().setDaemon(true)
            .setUncaughtExceptionHandler(UncaughtExceptionHandlers.defaultHandler(logger))
            .setNameFormat(pattern);
}

From source file:com.github.trask.sandbox.executors.DaemonExecutors.java

public static ExecutorService newSingleThreadExecutor(String name) {
    return Executors.newSingleThreadExecutor(
            new ThreadFactoryBuilder().setDaemon(true).setNameFormat(name + NAME_COUNTER_SUFFIX)
                    .setUncaughtExceptionHandler(new ExceptionHandler()).build());
}

From source file:org.apache.bookkeeper.common.util.ExecutorUtils.java

/**
 * Get a {@link ThreadFactory} suitable for use in the current environment.
 *
 * @param nameFormat to apply to threads created by the factory.
 * @param daemon     {@code true} if the threads the factory creates are daemon threads,
 *                   {@code false} otherwise.
 * @return a {@link ThreadFactory}./*from   w ww  . ja  v a  2  s . com*/
 */
public static ThreadFactory getThreadFactory(String nameFormat, boolean daemon) {
    ThreadFactory threadFactory = MoreExecutors.platformThreadFactory();
    return new ThreadFactoryBuilder().setThreadFactory(threadFactory).setDaemon(daemon)
            .setNameFormat(nameFormat).build();
}

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

public static ThreadPoolExecutor coreThreadsTimoutExecutor(final int numberOfThreads, final int threadPriority,
        final String threadNamePrefix, final long timeout, final TimeUnit unit) {
    final ThreadFactory factory = new ThreadFactoryBuilder().setPriority(threadPriority)
            .setNameFormat(threadNamePrefix + "%d").setDaemon(true).build();
    final ThreadPoolExecutor pool = new ThreadPoolExecutor(numberOfThreads, numberOfThreads, timeout, unit,
            new LinkedBlockingQueue<Runnable>(), factory);
    pool.allowCoreThreadTimeOut(true);//  w w  w .j  a va  2 s.co m
    return pool;
}

From source file:org.jdag.common.NamedThreadFactory.java

/**
 * Returns a <code>ThreadFactory that creates threads with the given simple
 * name./*from w w w . j a v  a  2s .co m*/
 */
public static ThreadFactory newNamedFactory(String simpleName) {
    ThreadFactoryBuilder tfBuilder = new ThreadFactoryBuilder();
    ThreadFactory namedFactory = tfBuilder.setNameFormat(simpleName).build();
    return namedFactory;
}