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:rapture.series.children.cleanup.DefaultFolderCleanupService.java

DefaultFolderCleanupService() {
    repoIdToInfo = new HashMap<>();
    executor = Executors.newSingleThreadScheduledExecutor(
            new ThreadFactoryBuilder().setNameFormat("FolderCleanup").setDaemon(true).build());
    Integer initialDelay = ConfigLoader.getConf().folderCleanup.initialDelay;
    Integer delay = ConfigLoader.getConf().folderCleanup.delay;
    executor.scheduleWithFixedDelay(new Runnable() {
        @Override//from   www.j  ava2 s.  co m
        public void run() {
            try {
                runCleanup();
            } catch (Exception e) {
                log.error(ExceptionToString.format(e));
            }
        }
    }, initialDelay, delay, TimeUnit.MILLISECONDS);

}

From source file:com.baifendian.swordfish.execserver.runner.flow.FlowRunnerManager.java

public FlowRunnerManager(Configuration conf) {
    this.flowDao = DaoFactory.getDaoInstance(FlowDao.class);

    int flowThreads = conf.getInt(Constants.EXECUTOR_FLOWRUNNER_THREADS, Constants.defaultFlowRunnerThreadNum);
    ThreadFactory flowThreadFactory = new ThreadFactoryBuilder().setNameFormat("Exec-Worker-FlowRunner")
            .build();/*from  ww w .  j  a v a 2s. c om*/
    flowExecutorService = Executors.newFixedThreadPool(flowThreads, flowThreadFactory);

    int nodeThreads = conf.getInt(Constants.EXECUTOR_NODERUNNER_THREADS, Constants.defaultNodeRunnerThreadNum);
    ThreadFactory nodeThreadFactory = new ThreadFactoryBuilder().setNameFormat("Exec-Worker-NodeRunner")
            .build();
    nodeExecutorService = Executors.newFixedThreadPool(nodeThreads, nodeThreadFactory);

    // ?? runningFlows ??
    Thread cleanThread = new Thread(() -> {
        while (true) {
            try {
                cleanFinishedFlows();
            } catch (Exception e) {
                logger.error("clean thread error ", e);
            } finally {
                try {
                    Thread.sleep(Constants.defaultCleanFinishFlowInterval);
                } catch (InterruptedException e) {
                }
            }
        }
    });

    cleanThread.setDaemon(true);
    cleanThread.setName("finishedFlowClean");
    cleanThread.start();
}

From source file:org.opendaylight.controller.config.manager.impl.osgi.BlankTransactionServiceTracker.java

public BlankTransactionServiceTracker(final BlankTransaction blankTransaction) {
    this(blankTransaction, DEFAULT_MAX_ATTEMPTS, Executors
            .newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("config-blank-txn-%d").build()));
}

From source file:org.apache.ranger.common.TimedExecutor.java

void initialize(TimedExecutorConfigurator configurator) {
    final ThreadFactory _ThreadFactory = new ThreadFactoryBuilder().setDaemon(true)
            .setNameFormat("timed-executor-pool-%d")
            .setUncaughtExceptionHandler(new LocalUncaughtExceptionHandler()).build();

    final BlockingQueue<Runnable> blockingQueue = new ArrayBlockingQueue<>(configurator.getBlockingQueueSize());

    _executorService = new LocalThreadPoolExecutor(configurator.getCoreThreadPoolSize(),
            configurator.getMaxThreadPoolSize(), configurator.getKeepAliveTime(),
            configurator.getKeepAliveTimeUnit(), blockingQueue, _ThreadFactory);
}

From source file:org.wso2.carbon.cluster.coordinator.rdbms.RDBMSMemberEventProcessor.java

public RDBMSMemberEventProcessor(String nodeId) {
    this.communicationBusContext = new RDBMSCommunicationBusContextImpl();
    ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("ClusterEventReaderTask-%d")
            .build();//from   w  w  w. j  a  v  a 2s  . com
    this.clusterMembershipReaderTaskScheduler = Executors.newSingleThreadScheduledExecutor(namedThreadFactory);
    addNewListenerTask(nodeId);
}

From source file:com.cloudera.oryx.kmeans.computation.local.ClusteringEvaluation.java

@Override
public List<KMeansEvaluationData> call() throws InterruptedException, ExecutionException {
    Config config = ConfigUtils.getDefaultConfig();
    EvaluationSettings settings = EvaluationSettings.create(config);

    ListeningExecutorService exec = MoreExecutors
            .listeningDecorator(Executors.newFixedThreadPool(config.getInt("model.parallelism"),
                    new ThreadFactoryBuilder().setNameFormat("KMEANS-%d").setDaemon(true).build()));
    List<ListenableFuture<KMeansEvaluationData>> futures = Lists.newArrayList();
    for (Integer nc : settings.getKValues()) {
        int loops = nc == 1 ? 1 : settings.getReplications();
        for (int i = 0; i < loops; i++) {
            futures.add(exec.submit(new EvaluationRun(weightedPoints, nc, i, settings)));
        }//from  w w w.  j a v a  2  s  .co  m
    }

    try {
        List<KMeansEvaluationData> evalData = Futures.allAsList(futures).get();
        KMeansEvalStrategy evalStrategy = settings.getEvalStrategy();
        if (evalStrategy != null) {
            List<ClusterValidityStatistics> best = evalStrategy.evaluate(
                    Lists.transform(evalData, new Function<KMeansEvaluationData, ClusterValidityStatistics>() {
                        @Override
                        public ClusterValidityStatistics apply(KMeansEvaluationData input) {
                            return input.getClusterValidityStatistics();
                        }
                    }));
            if (best.size() == 1) {
                ClusterValidityStatistics cvs = best.get(0);
                for (KMeansEvaluationData ed : evalData) {
                    if (cvs.getK() == ed.getK() && cvs.getReplica() == ed.getReplica()) {
                        return ImmutableList.of(ed);
                    }
                }
            }
        }
        return evalData;
    } finally {
        ExecutorUtils.shutdownAndAwait(exec);
    }
}

From source file:org.wso2.andes.kernel.slot.OrphanedSlotHandler.java

public OrphanedSlotHandler() {
    ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("AndesReassignSlotTaskExecutor")
            .build();//from  w  ww .ja  va 2 s.  c  om
    executor = Executors.newSingleThreadExecutor(namedThreadFactory);
    slotDeliveryWorkerManager = SlotDeliveryWorkerManager.getInstance();
    trackedSubscriptions = new ConcurrentHashMap<>();
}

From source file:com.facebook.presto.mysql.MySQLClientModule.java

@ForMySQLSchema
@Singleton/*from  w ww  .j a  va2 s. c o  m*/
@Provides
public ExecutorService createCachingMySQLSchemaExecutor(MYSQLConnectorId clientId,
        MySQLClientConfig mysqlClientConfig) {
    return Executors.newFixedThreadPool(mysqlClientConfig.getMaxSchemaRefreshThreads(),
            new ThreadFactoryBuilder().setDaemon(true).setNameFormat("mysql-schema-" + clientId + "-%d")
                    .build());
}

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

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

}

From source file:org.apache.pulsar.functions.windowing.triggers.TimeTriggerPolicy.java

public TimeTriggerPolicy(long millis, TriggerHandler handler, EvictionPolicy<T, ?> evictionPolicy,
        Context context) {//w  w w  . j av  a2  s . com
    this.duration = millis;
    this.handler = handler;
    this.evictionPolicy = evictionPolicy;
    ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("time-trigger-policy-%d")
            .setDaemon(true).build();
    this.executor = Executors.newSingleThreadScheduledExecutor(threadFactory);
    this.context = context;
}