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:io.qdb.server.input.InputManager.java

@Inject
public InputManager(EventBus eventBus, Repository repo, QueueManager queueManager,
        InputHandlerFactory handlerFactory, JsonService jsonService) throws IOException {
    this.repo = repo;
    this.queueManager = queueManager;
    this.handlerFactory = handlerFactory;
    this.jsonService = jsonService;
    this.pool = new ThreadPoolExecutor(1, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS,
            new SynchronousQueue<Runnable>(),
            new ThreadFactoryBuilder().setNameFormat("input-%d").setUncaughtExceptionHandler(this).build());
    eventBus.register(this);
    for (Input input : this.repo.findInputs(0, -1))
        inputChanged(input);//from  w w  w.j  a v  a  2 s . c  o m
}

From source file:com.uber.stream.kafka.chaperone.collector.RedisMonitor.java

public RedisMonitor(long checkIntervalInSec, String redisHost, int redisPort, long maxMemBytes,
        String maxMemPolicy) {// w w  w. j  ava 2  s .  com
    this.checkIntervalInSec = checkIntervalInSec;
    jedis = new Jedis(redisHost, redisPort);
    logger.info("RedisMonitor connected to Redis server: {}", jedis.ping());

    setRedisConfig("maxmemory", maxMemBytes + "");
    setRedisConfig("maxmemory-policy", maxMemPolicy);

    cronExecutor = Executors.newSingleThreadScheduledExecutor(
            new ThreadFactoryBuilder().setNameFormat("redis-monitor-%d").build());
}

From source file:org.eclipse.che.workspace.infrastructure.docker.local.projects.RemoveLocalProjectsFolderOnWorkspaceRemove.java

@Inject
public RemoveLocalProjectsFolderOnWorkspaceRemove(LocalProjectsFolderPathProvider workspaceFolderPathProvider) {
    this.workspaceFolderPathProvider = workspaceFolderPathProvider;
    executor = Executors.newCachedThreadPool(
            new ThreadFactoryBuilder().setNameFormat("RemoveLocalProjectsFolderOnWorkspaceRemove-%d")
                    .setUncaughtExceptionHandler(LoggingUncaughtExceptionHandler.getInstance()).build());
}

From source file:com.netflix.atlas.client.AtlasPlugin.java

private static ScheduledExecutorService getScheduledExecutorService(String nameFormat, int nThreads) {
    final ThreadFactory factory = new ThreadFactoryBuilder().setDaemon(true).setNameFormat(nameFormat).build();
    return Executors.newScheduledThreadPool(nThreads, factory);
}

From source file:org.springside.modules.utils.concurrent.ThreadUtil.java

/**
 * ThreadFactory???"pool-x-thread-y"//from   w  w  w  .  j  a  v  a 2s . com
 * 
 * Guava
 * 
 * @see ThreadFactoryBuilder#build()
 */
public static ThreadFactory buildThreadFactory(@NotNull String threadNamePrefix) {
    return new ThreadFactoryBuilder().setNameFormat(threadNamePrefix + "-%d").build();
}

From source file:org.renyan.leveldb.util.Finalizer.java

public synchronized void addCleanup(T item, Callable<?> cleanup) {
    Preconditions.checkNotNull(item, "item is null");
    Preconditions.checkNotNull(cleanup, "cleanup is null");
    Preconditions.checkState(!destroyed, "%s is destroyed", getClass().getName());

    if (executor == null) {
        // create executor
        ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("FinalizerQueueProcessor-%d")
                .setDaemon(true).build();
        executor = Executors.newFixedThreadPool(threads, threadFactory);

        // start queue processor jobs
        for (int i = 0; i < threads; i++) {
            executor.submit(new FinalizerQueueProcessor());
        }/*from   w  w w . ja v a2s. c  o m*/
    }

    // create a reference to the item so we are notified when it is garbage collected
    FinalizerPhantomReference<T> reference = new FinalizerPhantomReference<T>(item, referenceQueue, cleanup);

    // we must keep a strong reference to the reference object so we are notified when the item
    // is no longer reachable (if the reference object is garbage collected we are never notified)
    references.put(reference, Boolean.TRUE);
}

From source file:org.apache.bookkeeper.bookie.SortedLedgerStorage.java

@Override
public void initialize(ServerConfiguration conf, LedgerManager ledgerManager,
        LedgerDirsManager ledgerDirsManager, LedgerDirsManager indexDirsManager,
        final CheckpointSource checkpointSource, StatsLogger statsLogger) throws IOException {
    super.initialize(conf, ledgerManager, ledgerDirsManager, indexDirsManager, checkpointSource, statsLogger);
    this.memTable = new EntryMemTable(conf, checkpointSource, statsLogger);
    this.scheduler = Executors
            .newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setNameFormat("SortedLedgerStorage-%d")
                    .setPriority((Thread.NORM_PRIORITY + Thread.MAX_PRIORITY) / 2).build());
}

From source file:rapture.exchange.rabbitmq.MessageConsumer.java

public MessageConsumer(Channel channel, String tag, QueueHandler handler, String queueName) {
    super(channel);
    this.tag = tag;
    this.handler = handler;
    String threadPoolSizeString = MultiValueConfigLoader.getConfig("RUNNER-rabbitMQConsumerPoolSize", "50");
    int threadPoolSize = Integer.parseInt(threadPoolSizeString);
    service = Executors.newFixedThreadPool(threadPoolSize,
            new ThreadFactoryBuilder().setNameFormat("MessageConsumer-" + queueName + "-%d").build());
}

From source file:org.apache.pig.backend.hadoop.PigATSClient.java

private PigATSClient() {
    if (executor == null) {
        executor = Executors.newSingleThreadExecutor(
                new ThreadFactoryBuilder().setDaemon(true).setNameFormat("ATS Logger %d").build());
        YarnConfiguration yarnConf = new YarnConfiguration();
        timelineClient = TimelineClient.createTimelineClient();
        timelineClient.init(yarnConf);/*from w ww.  ja  v  a2s  .c o m*/
        timelineClient.start();
    }
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            timelineClient.stop();
            executor.shutdownNow();
            executor = null;
        }
    });
    log.info("Created ATS Hook");
}

From source file:com.github.benmanes.caffeine.cache.Stresser.java

public Stresser() {
    ThreadFactory threadFactory = new ThreadFactoryBuilder().setPriority(Thread.MAX_PRIORITY).setDaemon(true)
            .build();//ww  w  .j  ava 2  s  . co m
    Executors.newSingleThreadScheduledExecutor(threadFactory).scheduleAtFixedRate(this::status, STATUS_INTERVAL,
            STATUS_INTERVAL, SECONDS);
    cache = Caffeine.newBuilder().maximumSize(operation.maxEntries).recordStats().build(key -> key);
    local = (BoundedLocalCache<Integer, Integer>) cache.asMap();
    ints = new Integer[TOTAL_KEYS];
    Arrays.setAll(ints, key -> {
        cache.put(key, key);
        return key;
    });
    cache.cleanUp();
    stopwatch = Stopwatch.createStarted();
    status();
}