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.nickelproject.nickel.mapReduce.ThreadedMapper.java

/**
 * Creates a new ThreadedMapper backed by a thread-pool of the given size.
 * /* w w w. j  a  v  a 2s .  c om*/
 * @param pNumThreads the (fixed) size of the thread-pool
 */
public ThreadedMapper(@Named("NumMapperThreads") final int pNumThreads) {
    this(pNumThreads, pNumThreads, new ThreadFactoryBuilder().setDaemon(true).build());
}

From source file:org.eclipse.che.ide.extension.maven.server.core.BufferOutputFixedRateSender.java

public BufferOutputFixedRateSender(String channel, long delay) {
    this.channel = channel;
    ThreadFactory threadFactory = new ThreadFactoryBuilder()
            .setNameFormat(BufferOutputFixedRateSender.class.getSimpleName() + "-%d").setDaemon(true).build();

    executor = Executors.newScheduledThreadPool(1, threadFactory);

    executor.scheduleAtFixedRate(this::sendMessage, 1_000, delay, MILLISECONDS);
}

From source file:org.restcomm.media.bootstrap.ioc.provider.ListeningScheduledExecutorServiceProvider.java

@Override
public ListeningScheduledExecutorService get() {
    ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("mgcp-%d").build();
    // TODO set uncaught exception handler

    // ThreadPoolExecutor executor = new ThreadPoolExecutor(POOL_SIZE, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new
    // SynchronousQueue<Runnable>(), threadFactory);
    // executor.allowCoreThreadTimeOut(false);
    // Executors.newScheduledThreadPool(POOL_SIZE, threadFactory);
    // return MoreExecutors.listeningDecorator(executor);

    ScheduledThreadPoolExecutor executor = (ScheduledThreadPoolExecutor) Executors
            .newScheduledThreadPool(POOL_SIZE, threadFactory);
    executor.prestartAllCoreThreads();//  ww  w. j  a v a2 s .  c om
    executor.setRemoveOnCancelPolicy(true);
    return MoreExecutors.listeningDecorator(executor);
}

From source file:org.apache.james.util.concurrent.NamedThreadFactory.java

private NamedThreadFactory(String name) {
    this.name = name;
    this.threadFactory = new ThreadFactoryBuilder().setNameFormat(name + "-%d").build();
}

From source file:com.xyxy.platform.examples.showcase.demos.schedule.JdkTimerJob.java

@PostConstruct
public void start() throws Exception {
    Validate.isTrue(period > 0);//from  ww  w  .jav a 2  s  . c  o  m

    // ?schedule, Spring TaskUtilsLOG_AND_SUPPRESS_ERROR_HANDLER?
    Runnable task = TaskUtils.decorateTaskWithErrorHandler(this, null, true);

    // ?SechdulerExecutor,guavaThreadFactoryBuilder???
    scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(
            new ThreadFactoryBuilder().setNameFormat("JdkTimerJob-%1$d").build());

    // scheduleAtFixedRatefixRate() ?.
    // scheduleAtFixedDelay() ???.
    scheduledExecutorService.scheduleAtFixedRate(task, initialDelay, period, TimeUnit.SECONDS);
}

From source file:org.apache.aurora.scheduler.app.local.simulator.FakeSlaves.java

@Inject
FakeSlaves(Set<Offer> offers, FakeMaster master) {
    this.offers = requireNonNull(offers);
    this.master = requireNonNull(master);
    this.executor = Executors.newSingleThreadScheduledExecutor(
            new ThreadFactoryBuilder().setDaemon(true).setNameFormat("FakeSlave=%d").build());
}

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

public void startServer(SConfiguration config) {

    ScheduledExecutorService executor = Executors.newScheduledThreadPool(15,
            new ThreadFactoryBuilder().setNameFormat("OlapServer-%d").setDaemon(true).build());
    this.factory = new NioServerSocketChannelFactory(executor, 2, executor, 10);

    SpliceLogUtils.info(LOG, "Olap Server starting (binding to port %s)...", port);

    ServerBootstrap bootstrap = new ServerBootstrap(factory);

    // Instantiate handler once and share it
    OlapJobRegistry registry = new MappedJobRegistry(config.getOlapClientTickTime(),
            config.getOlapServerTickLimit(), TimeUnit.MILLISECONDS);
    ChannelHandler submitHandler = new OlapRequestHandler(config, registry, clock,
            config.getOlapClientTickTime());
    ChannelHandler statusHandler = new OlapStatusHandler(registry);
    ChannelHandler cancelHandler = new OlapCancelHandler(registry);

    bootstrap.setPipelineFactory(new OlapPipelineFactory(submitHandler, cancelHandler, statusHandler));
    bootstrap.setOption("tcpNoDelay", false);
    bootstrap.setOption("child.tcpNoDelay", false);
    bootstrap.setOption("child.keepAlive", true);
    bootstrap.setOption("child.reuseAddress", true);

    this.channel = bootstrap.bind(new InetSocketAddress(getPortNumber()));
    ((InetSocketAddress) channel.getLocalAddress()).getPort();

    SpliceLogUtils.info(LOG, "Olap Server started.");

}

From source file:org.jclouds.concurrent.config.ScheduledExecutorServiceModule.java

private static ListeningScheduledExecutorService newScheduledThreadPoolNamed(String name, int maxCount) {
    ThreadFactory factory = new ThreadFactoryBuilder().setNameFormat(name)
            .setThreadFactory(defaultThreadFactory()).build();
    return listeningDecorator(maxCount == 0 ? newSingleThreadScheduledExecutor(factory)
            : newScheduledThreadPool(maxCount, factory));
}

From source file:org.eclipse.che.commons.schedule.executor.ThreadPullLauncher.java

/**
 * @param corePoolSize//from  w w w  .  ja  v a  2  s . c  o m
 *         the number of threads to keep in the pool, even
 *         if they are idle, unless {@code allowCoreThreadTimeOut} is set
 */
@Inject
public ThreadPullLauncher(@Named("schedule.core_pool_size") Integer corePoolSize) {
    this.service = new CronThreadPoolExecutor(corePoolSize,
            new ThreadFactoryBuilder().setNameFormat("Annotated-scheduler-%d")
                    .setUncaughtExceptionHandler(LoggingUncaughtExceptionHandler.getInstance()).setDaemon(false)
                    .build());
}

From source file:org.atc.DisruptorBasedPublisher.java

DisruptorBasedPublisher(int batchSize, SimplePublisher publisher, AtomicInteger sentCount, Meter publishRate) {

    ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
            .setNameFormat("DisruptorPublisherThread-id-" + publisher.getConfigs().getId() + "-%d").build();
    executorPool = Executors.newCachedThreadPool(namedThreadFactory);
    int bufferSize = DEFAULT_DISRUPTOR_BUFFER_SIZE;

    disruptor = new Disruptor<PublishEvent>(PublishEvent.getFactory(), bufferSize, executorPool,
            ProducerType.SINGLE, new BlockingWaitStrategy());

    disruptor.handleEventsWith(new TxPublishHandler(batchSize, publisher, sentCount, publishRate));
    disruptor.start();// w  ww. java  2s  .  c om
}