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.proofpoint.event.monitor.MainModule.java

@Provides
@Singleton/*  w  w w  .  java 2  s.c  o m*/
@MonitorExecutorService
public ScheduledExecutorService createMonitorExecutorService() {
    return Executors.newScheduledThreadPool(5,
            new ThreadFactoryBuilder().setDaemon(true).setNameFormat("monitor-%s").build());
}

From source file:com.griddynamics.jagger.util.ConfigurableExecutor.java

private ThreadPoolExecutor delegate() {
    if (delegate == null) {
        synchronized (lock) {
            if (delegate == null) {
                ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat(nameFormat)
                        .setUncaughtExceptionHandler(ExceptionLogger.INSTANCE).build();
                delegate = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, 180, TimeUnit.SECONDS,
                        new SynchronousQueue<Runnable>(), threadFactory);

            }/*  www. j av  a 2s.co  m*/
        }
    }
    return delegate;
}

From source file:com.cinchapi.concourse.util.Producer.java

/**
 * Construct a new instance./*from ww w . j a  v a  2  s .  c o  m*/
 * 
 * @param supplier
 */
public Producer(final Callable<T> supplier) {
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            try {
                for (;;) {
                    T element = supplier.call();
                    queue.put(element);
                }
            } catch (Exception e) {
                throw Throwables.propagate(e);
            }

        }

    };

    // Create threads that will continuously try to insert elements into the
    // queue, blocking until one of the elements is taken.
    int count = Runtime.getRuntime().availableProcessors();
    ExecutorService executor = Executors.newFixedThreadPool(count,
            new ThreadFactoryBuilder().setDaemon(true).build());
    for (int i = 0; i < count; ++i) {
        executor.execute(runnable);
    }

}

From source file:co.paralleluniverse.fibers.ws.rs.client.AsyncClientBuilder.java

private static ClientConfig addDefaultConfigurations(Configuration configuration) {
    // currently there is no usage with the singleThreadPool variable due to jersey bug. See below.
    final ExecutorServiceProvider singleThreadPool = new ExecutorServiceProvider() {
        private ExecutorService tp = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder()
                .setDaemon(true).setNameFormat("jersey-puniverse-single-worker-%d").build());

        @Override//from  ww w  .  j  a  va 2 s .c  om
        public ExecutorService getExecutorService() {
            return tp;
        }

        @Override
        public void dispose(ExecutorService es) {
        }
    };
    final ClientConfig config = new ClientConfig().
    // This is commented since, jersey has major problem (since ~2.5) - it blocks the calling thread !!!
    // When this bug will be fixed we should uncomment this line in order to enable a lot of concurrent open requsets                
    //                register(singleThreadPool, RequestExecutorProvider.class).
            property(ClientProperties.ASYNC_THREADPOOL_SIZE, 20);
    if (configuration != null)
        config.loadFrom(configuration);
    if (config.getConnectorProvider() == null)
        config.connectorProvider(new JettyConnectorProvider());
    return config;
}

From source file:com.tuplejump.stargate.IndexingService.java

public IndexingService(AtomicLong reads, AtomicLong writes) {
    support = new HashMap<>();
    this.reads = reads;
    this.writes = writes;
    ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("SGRingBuffer-Thread-%d")
            .build();/*  w  ww .  ja v a  2  s  . co m*/
    executorService = Executors.newFixedThreadPool(numWorkers, namedThreadFactory);
    disruptor = new Disruptor<>(eventFactory, bufferSize, executorService);
    ringBuffer = disruptor.getRingBuffer();

    ExceptionHandler exceptionHandler = new FatalExceptionHandler();
    disruptor.handleExceptionsWith(exceptionHandler);

    EventHandler<IndexEntryEvent>[] eventHandlers = new EventHandler[numWorkers];
    for (int i = 0; i < numWorkers; i++) {
        eventHandlers[i] = new IndexEventHandler(this, i, numWorkers);
    }
    disruptor.handleEventsWith(eventHandlers);

    disruptor.start();
}

From source file:io.bitsquare.common.util.Utilities.java

public static ThreadPoolExecutor getThreadPoolExecutor(String name, int corePoolSize, int maximumPoolSize,
        long keepAliveTimeInSec) {
    final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat(name).setDaemon(true).build();
    ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTimeInSec,
            TimeUnit.SECONDS, new ArrayBlockingQueue<>(maximumPoolSize), threadFactory);
    executor.allowCoreThreadTimeOut(true);
    executor.setRejectedExecutionHandler((r, e) -> {
        log.debug("RejectedExecutionHandler called");
    });//  w ww.ja  v a  2 s.c om
    return executor;
}

From source file:org.eclipse.che.api.project.server.importer.ProjectImportOutputWSLineConsumer.java

public ProjectImportOutputWSLineConsumer(String projectName, String workspaceId, int delayBetweenMessages) {
    this.projectName = projectName;
    this.workspaceId = workspaceId;
    lineToSendQueue = new ArrayBlockingQueue<>(1024);
    executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder()
            .setNameFormat(ProjectImportOutputWSLineConsumer.class.getSimpleName() + "-%d").setDaemon(true)
            .setUncaughtExceptionHandler(LoggingUncaughtExceptionHandler.getInstance()).build());
    executor.scheduleAtFixedRate(new Runnable() {
        @Override/* ww  w .  ja  v  a  2 s .  c om*/
        public void run() {
            String lineToSend = null;
            while (!lineToSendQueue.isEmpty()) {
                lineToSend = lineToSendQueue.poll();
            }
            if (lineToSend == null) {
                return;
            }
            sendMessage(lineToSend);
        }
    }, 0, delayBetweenMessages, TimeUnit.MILLISECONDS);
    lineCounter = new AtomicInteger(1);
}

From source file:org.apache.nutch.parse.ParseUtil.java

/**
 * /*from w  ww . ja va2  s.c o  m*/
 * @param conf
 */
public ParseUtil(Configuration conf) {
    this.parserFactory = new ParserFactory(conf);
    maxParseTime = conf.getInt("parser.timeout", 30);
    executorService = Executors
            .newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("parse-%d").setDaemon(true).build());
}

From source file:fr.ymanvieu.trading.config.SchedulerConfig.java

@Bean(destroyMethod = "shutdown")
public ScheduledExecutorService taskScheduler() {
    ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("rateScheduler-%d").build();
    return Executors.newScheduledThreadPool(3, namedThreadFactory);
}

From source file:com.vsct.dt.hesperides.indexation.ElasticSearchIndexationExecutor.java

public ElasticSearchIndexationExecutor(final ElasticSearchClient elasticSearchClient, final int nRetries,
        final int waitBeforeRetryMs) {
    this.nRetries = nRetries;
    this.waitBeforeRetryMs = waitBeforeRetryMs;
    this.elasticSearchClient = elasticSearchClient;
    ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(false)
            .setNameFormat("ElasticSearchIndexer-%d").build();
    this.singleThreadPool = Executors.newFixedThreadPool(1, threadFactory);
}