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.eclipse.che.api.workspace.server.hc.probe.ProbeScheduler.java

@Inject
public ProbeScheduler(@Named("che.workspace.probe_pool_size") int probeSchedulerPoolSize) {
    probesExecutor = new ScheduledThreadPoolExecutor(probeSchedulerPoolSize,
            new ThreadFactoryBuilder().setDaemon(true).setNameFormat("ServerProbes-%s").build());
    timeouts = new Timer("ServerProbesTimeouts", true);
    probesFutures = new ConcurrentHashMap<>();
}

From source file:com.proofpoint.event.collector.AsyncBatchProcessor.java

public AsyncBatchProcessor(String name, BatchHandler<T> handler, BatchProcessorConfig config) {
    checkNotNull(name, "name is null");
    checkNotNull(handler, "handler is null");

    this.handler = handler;
    this.maxBatchSize = checkNotNull(config, "config is null").getMaxBatchSize();
    this.queue = new ArrayBlockingQueue<>(config.getQueueSize());

    this.executor = Executors.newSingleThreadExecutor(
            new ThreadFactoryBuilder().setNameFormat(format("batch-processor-%s", name)).build());
}

From source file:org.apache.s4.core.staging.LoadSheddingSenderExecutorServiceFactory.java

@Override
public ExecutorService create() {
    boolean remote = (this instanceof RemoteSendersExecutorServiceFactory);
    ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true)
            .setNameFormat(remote ? "remote-sender-%d" : "sender-%d").build();

    RejectedExecutionHandler rejectedExecutionHandler = (remote ? new RejectedExecutionHandler() {

        // from a remote sender
        @Override/*from   w w  w.  jav a  2  s  . c  o  m*/
        public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
            metrics.droppedEventInRemoteSender();
        }
    } : new RejectedExecutionHandler() {

        @Override
        public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
            metrics.droppedEventInSender();
        }
    });
    ThreadPoolExecutor tpe = new ThreadPoolExecutor(parallelism, parallelism, 60, TimeUnit.SECONDS,
            new ArrayBlockingQueue<Runnable>(workQueueSize), threadFactory, rejectedExecutionHandler);
    tpe.allowCoreThreadTimeOut(true);
    return tpe;
}

From source file:org.opendaylight.infrautils.utils.concurrent.ThreadFactoryProvider.java

@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED") // OK to ignore guavaBuilder.setPriority's return this in ifPresent()
public ThreadFactory get() {
    ThreadFactoryBuilder guavaBuilder = new ThreadFactoryBuilder().setNameFormat(namePrefix() + "-%d")
            .setUncaughtExceptionHandler(LoggingThreadUncaughtExceptionHandler.toLogger(logger()))
            .setDaemon(daemon());/*w  w  w  .  ja v  a 2  s  .  c o m*/
    priority().ifPresent(guavaBuilder::setPriority);
    logger().info("ThreadFactory created: {}", namePrefix());
    return guavaBuilder.build();
}

From source file:de.uniulm.omi.cloudiator.lance.lca.EnvContext.java

EnvContext(Map<String, String> ctxParam) {
    hostContext = ctxParam;/*w  w w .jav a  2 s  .c om*/
    final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("EnvContextExecutor-%d")
            .build();
    this.executorService = new LoggingScheduledThreadPoolExecutor(4, threadFactory);
}

From source file:org.graylog2.bindings.providers.ClusterEventBusProvider.java

private ExecutorService executorService(int nThreads) {
    final ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true)
            .setNameFormat("cluster-eventbus-handler-%d").build();
    return new InstrumentedExecutorService(Executors.newFixedThreadPool(nThreads, threadFactory),
            metricRegistry, name("cluster-eventbus", "executor-service"));
}

From source file:org.wisdom.executors.ManagedScheduledExecutorServiceImpl.java

public ManagedScheduledExecutorServiceImpl(String name, ThreadType tu, long hungTime, int coreSize,
        int priority, List<ExecutionContextService> ecs) {

    super(name, hungTime, ecs);
    ThreadFactoryBuilder builder = new ThreadFactoryBuilder().setDaemon(tu == ThreadType.DAEMON)
            .setNameFormat(name + "-%s").setPriority(priority)
            .setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
                @Override// w ww . ja v a 2  s . co  m
                public void uncaughtException(Thread t, Throwable e) {
                    logger.error("Uncaught exception in thread '{}'", t.getName(), e);
                }
            });

    setInternalPool(new ScheduledThreadPoolExecutor(coreSize, builder.build()));
}

From source file:org.apache.hadoop.mapreduce.v2.app.taskclean.TaskCleanerImpl.java

public void start() {
    ThreadFactory tf = new ThreadFactoryBuilder().setNameFormat("TaskCleaner #%d").build();
    launcherPool = new ThreadPoolExecutor(5, 5, 1, TimeUnit.HOURS, new LinkedBlockingQueue<Runnable>(), tf);
    eventHandlingThread = new Thread(new Runnable() {
        @Override/*from w w w.  ja  v  a2 s.  c o  m*/
        public void run() {
            TaskCleanupEvent event = null;
            while (!Thread.currentThread().isInterrupted()) {
                try {
                    event = eventQueue.take();
                } catch (InterruptedException e) {
                    LOG.error("Returning, interrupted : " + e);
                    return;
                }
                // the events from the queue are handled in parallel
                // using a thread pool
                launcherPool.execute(new EventProcessor(event));
            }
        }
    });
    eventHandlingThread.setName("TaskCleaner Event Handler");
    eventHandlingThread.start();
    super.start();
}

From source file:org.apache.storm.windowing.TimeTriggerPolicy.java

public TimeTriggerPolicy(long millis, TriggerHandler handler, EvictionPolicy<T, ?> evictionPolicy) {
    this.duration = millis;
    this.handler = handler;
    ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("time-trigger-policy-%d")
            .setDaemon(true).build();/*from   w ww  .  j  a va 2s  .  c  o  m*/
    this.executor = Executors.newSingleThreadScheduledExecutor(threadFactory);
    this.evictionPolicy = evictionPolicy;
}

From source file:com.moz.fiji.commons.RefreshingReference.java

/**
 * Static factory constructor. Allows the user to pass in a name for the thread
 * the scheduler will run on.//  w  w  w  .  ja va2s  .c o  m
 *
 * @param refreshPeriod Configures the refresh rate for the scheduler.
 * @param timeUnit Specifies the unit of time for the refreshPeriod.
 * @param refreshingLoader Used to initialize and refresh the cached value.
 * @param name The name of the thread the scheduler will run on.
 * @param loopController Used to deterministically control refresh cycles during testing.
 * @param <U> The type that will be cached.
 * @return A new RefreshingReference.
 */
public static <U> RefreshingReference<U> create(final Long refreshPeriod, final TimeUnit timeUnit,
        final RefreshingLoader<U> refreshingLoader, final String name,
        final Optional<LoopController> loopController) {
    ThreadFactoryBuilder builder = new ThreadFactoryBuilder().setNameFormat(name + "-%d");
    return new RefreshingReference<>(refreshPeriod, timeUnit, refreshingLoader, builder, loopController);
}