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.wso2.andes.server.cluster.coordination.rdbms.RDBMSClusterNotificationListenerManager.java

/**
 * Schedules the {@link ClusterEventReaderTask} to run with the configured interval in the broker.xml.
 *//*from  w ww .  j a  v  a2  s  . c  o  m*/
private void scheduleClusterNotificationReader() {
    ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("ClusterEventReaderTask-%d").build();
    int clusterEventReaderInterval = AndesConfigurationManager
            .readValue(AndesConfiguration.CLUSTER_EVENT_SYNC_INTERVAL);
    scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(threadFactory);
    scheduledExecutorService.scheduleWithFixedDelay(new ClusterEventReaderTask(), clusterEventReaderInterval,
            clusterEventReaderInterval, TimeUnit.MILLISECONDS);
    log.info("RDBMS cluster event listener started with an interval of: " + clusterEventReaderInterval + "ms.");
}

From source file:org.apache.phoenix.job.JobManager.java

public static ThreadPoolExecutor createThreadPoolExec(int keepAliveMs, int size, int queueSize,
        boolean useInstrumentedThreadPool) {
    BlockingQueue<Runnable> queue;
    if (queueSize == 0) {
        queue = new SynchronousQueue<Runnable>(); // Specialized for 0 length.
    } else {/*from ww w .j  av  a2s . co  m*/
        queue = new JobManager<Runnable>(queueSize);
    }
    String name = "phoenix-" + PHOENIX_POOL_INDEX.getAndIncrement();
    ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat(name + "-thread-%s").setDaemon(true)
            .setThreadFactory(new ContextClassLoaderThreadFactory(JobManager.class.getClassLoader())).build();
    ThreadPoolExecutor exec;
    if (useInstrumentedThreadPool) {
        // For thread pool, set core threads = max threads -- we don't ever want to exceed core threads, but want to go up to core threads *before* using the queue.
        exec = new InstrumentedThreadPoolExecutor(name, size, size, keepAliveMs, TimeUnit.MILLISECONDS, queue,
                threadFactory) {
            @Override
            protected <T> RunnableFuture<T> newTaskFor(Callable<T> call) {
                return new InstrumentedJobFutureTask<T>(call);
            }

            @Override
            protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) {
                return new InstrumentedJobFutureTask<T>(runnable, value);
            }
        };
    } else {
        // For thread pool, set core threads = max threads -- we don't ever want to exceed core threads, but want to go up to core threads *before* using the queue.
        exec = new ThreadPoolExecutor(size, size, keepAliveMs, TimeUnit.MILLISECONDS, queue, threadFactory) {
            @Override
            protected <T> RunnableFuture<T> newTaskFor(Callable<T> call) {
                // Override this so we can create a JobFutureTask so we can extract out the parentJobId (otherwise, in the default FutureTask, it is private). 
                return new JobFutureTask<T>(call);
            }

            @Override
            protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) {
                return new JobFutureTask<T>(runnable, value);
            }
        };
    }
    exec.allowCoreThreadTimeOut(true); // ... and allow core threads to time out.  This just keeps things clean when idle, and is nice for ftests modes, etc., where we'd especially like these not to linger.
    return exec;
}

From source file:org.eclipse.che.plugin.nodejsdbg.server.NodeJsDebugProcess.java

private NodeJsDebugProcess(String outputSeparator, String... options) throws NodeJsDebuggerException {
    this.observers = new CopyOnWriteArrayList<>();
    this.outputSeparator = outputSeparator;

    process = initializeNodeJsDebugProcess(options);
    processWriter = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));

    executor = Executors.newScheduledThreadPool(1,
            new ThreadFactoryBuilder().setNameFormat("nodejs-debugger-%d")
                    .setUncaughtExceptionHandler(LoggingUncaughtExceptionHandler.getInstance()).setDaemon(true)
                    .build());//from w ww  .  j  a  va2s  . c  o  m

    OutputReader outputReader = new OutputReader(process, outputSeparator, this::notifyObservers);
    executor.scheduleWithFixedDelay(outputReader, 0, 100, TimeUnit.MILLISECONDS);
}

From source file:org.graylog.collector.file.ChunkReaderScheduler.java

public ChunkReaderScheduler(final Input input, final ArrayBlockingQueue<FileChunk> chunkQueue,
        final int readerBufferSize, final long readerInterval,
        final FileInput.InitialReadPosition initialReadPosition) {
    this.input = input;
    this.chunkQueue = chunkQueue;
    this.readerBufferSize = readerBufferSize;
    this.readerInterval = readerInterval;
    this.initialReadPosition = initialReadPosition;

    // TODO Make the thread size configurable.
    this.scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setDaemon(false)
            .setNameFormat("chunkreader-scheduler-thread-" + input.getId() + "-%d").build());
}

From source file:org.apache.flume.node.PollingPropertiesFileConfigurationProvider.java

@Override
public void start() {
    LOGGER.info("Configuration provider starting");

    Preconditions.checkState(file != null, "The parameter file must not be null");

    executorService = Executors.newSingleThreadScheduledExecutor(
            new ThreadFactoryBuilder().setNameFormat("conf-file-poller-%d").build());

    FileWatcherRunnable fileWatcherRunnable = new FileWatcherRunnable(file, counterGroup);

    executorService.scheduleWithFixedDelay(fileWatcherRunnable, 0, interval, TimeUnit.SECONDS);

    lifecycleState = LifecycleState.START;

    LOGGER.debug("Configuration provider started");
}

From source file:org.eclipse.che.api.agent.server.terminal.MachineTerminalLauncher.java

@Inject
public MachineTerminalLauncher(EventService eventService,
        Set<MachineImplSpecificTerminalLauncher> machineImplLaunchers,
        CheEnvironmentEngine cheEnvironmentEngine) {
    this.eventService = eventService;
    this.terminalLaunchers = machineImplLaunchers.stream()
            .collect(toMap(MachineImplSpecificTerminalLauncher::getMachineType, Function.identity()));
    this.cheEnvironmentEngine = cheEnvironmentEngine;
    this.executor = Executors.newCachedThreadPool(
            new ThreadFactoryBuilder().setNameFormat("MachineTerminalLauncher-%d").setDaemon(true).build());

}

From source file:io.druid.guice.DruidProcessingModule.java

@Provides
@BackgroundCaching//from   ww w  .  j  a  v a  2 s .  c o m
@LazySingleton
public ExecutorService getBackgroundExecutorService(CacheConfig cacheConfig) {
    if (cacheConfig.getNumBackgroundThreads() > 0) {
        return Executors.newFixedThreadPool(cacheConfig.getNumBackgroundThreads(),
                new ThreadFactoryBuilder().setNameFormat("background-cacher-%d").setDaemon(true)
                        .setPriority(Thread.MIN_PRIORITY).build());
    } else {
        return MoreExecutors.sameThreadExecutor();
    }
}

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

@Provides
@EventTap//  w  ww .  ja v  a 2  s  . co  m
public ScheduledExecutorService createExecutor() {
    return newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setNameFormat("event-tap-%s").build());
}

From source file:org.eclipse.che.plugin.docker.client.CgroupOOMDetector.java

public CgroupOOMDetector(URI dockerDaemonUri, DockerConnectorProvider dockerConnectorProvider) {
    this.dockerDaemonUri = dockerDaemonUri;
    this.dockerConnector = dockerConnectorProvider.get();
    this.oomDetectors = new ConcurrentHashMap<>();
    this.executor = Executors
            .newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("CgroupOOMDetector-%d")
                    .setUncaughtExceptionHandler(LoggingUncaughtExceptionHandler.getInstance()).setDaemon(true)
                    .build());// w  w w. jav  a  2 s. co m
}

From source file:org.opendaylight.faas.fabric.vlan.FabricContext.java

public FabricContext(FabricId fabricId, DataBroker databroker, List<GatewayMac> availableMacs) {
    this.fabricId = fabricId;
    this.databroker = databroker;
    this.availableMacs = availableMacs;

    final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat(fabricId.getValue() + " - %d")
            .build();//  w  w w  .  ja v a2  s  .  c  o m
    this.executor = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor(threadFactory));
}