Example usage for java.util.concurrent ThreadFactory ThreadFactory

List of usage examples for java.util.concurrent ThreadFactory ThreadFactory

Introduction

In this page you can find the example usage for java.util.concurrent ThreadFactory ThreadFactory.

Prototype

ThreadFactory

Source Link

Usage

From source file:com.linkedin.pinot.controller.helix.core.SegmentDeletionManager.java

SegmentDeletionManager(String localDiskDir, HelixAdmin helixAdmin, String helixClusterName,
        ZkHelixPropertyStore<ZNRecord> propertyStore) {
    _localDiskDir = localDiskDir;/*from   w ww .ja  va 2s.co  m*/
    _helixAdmin = helixAdmin;
    _helixClusterName = helixClusterName;
    _propertyStore = propertyStore;

    _executorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
        @Override
        public Thread newThread(Runnable runnable) {
            Thread thread = new Thread(runnable);
            thread.setName("PinotHelixResourceManagerExecutorService");
            return thread;
        }
    });
}

From source file:org.apache.hadoop.hive.ql.txn.AcidHouseKeeperService.java

@Override
public void start(HiveConf hiveConf) throws Exception {
    HiveTxnManager mgr = TxnManagerFactory.getTxnManagerFactory().getTxnManager(hiveConf);
    if (!mgr.supportsAcid()) {
        LOG.info(AcidHouseKeeperService.class.getName() + " not started since " + mgr.getClass().getName()
                + " does not support Acid.");
        return;//there are no transactions in this case
    }//  w  w w  . j av  a 2s .com
    pool = Executors.newScheduledThreadPool(1, new ThreadFactory() {
        private final AtomicInteger threadCounter = new AtomicInteger();

        @Override
        public Thread newThread(Runnable r) {
            return new Thread(r, "DeadTxnReaper-" + threadCounter.getAndIncrement());
        }
    });
    TimeUnit tu = TimeUnit.MILLISECONDS;
    pool.scheduleAtFixedRate(new TimedoutTxnReaper(hiveConf, this),
            hiveConf.getTimeVar(HiveConf.ConfVars.HIVE_TIMEDOUT_TXN_REAPER_START, tu),
            hiveConf.getTimeVar(HiveConf.ConfVars.HIVE_TIMEDOUT_TXN_REAPER_INTERVAL, tu),
            TimeUnit.MILLISECONDS);
    LOG.info("Started " + this.getClass().getName() + " with delay/interval = "
            + hiveConf.getTimeVar(HiveConf.ConfVars.HIVE_TIMEDOUT_TXN_REAPER_START, tu) + "/"
            + hiveConf.getTimeVar(HiveConf.ConfVars.HIVE_TIMEDOUT_TXN_REAPER_INTERVAL, tu) + " " + tu);
}

From source file:org.mc4j.ems.impl.jmx.connection.PooledConnectionTracker.java

protected void initTracker() {
    // TODO GH: Build registration system
    RefreshItem connectionRefresh = new ConnectionRefresh(20000, connection);
    refreshItems.add(connectionRefresh);

    RefreshItem attributeRefresh = new MBeanRefresh(20000);
    refreshItems.add(attributeRefresh);/*  w ww  .j av a  2s .co m*/

    // Give names to the threads with a custom thread factory
    executor = new ScheduledThreadPoolExecutor(POOL_SIZE, new ThreadFactory() {
        private AtomicInteger index = new AtomicInteger(1);

        public Thread newThread(Runnable r) {
            return new Thread(r, "EMS-ConnectionTracker-" + index.getAndIncrement());
        }
    });

    executor.scheduleAtFixedRate(connectionRefresh, 1000, connectionRefresh.getUpdateDelay(),
            TimeUnit.MILLISECONDS);
    executor.scheduleAtFixedRate(attributeRefresh, 1500, attributeRefresh.getUpdateDelay(),
            TimeUnit.MILLISECONDS);

}

From source file:org.apache.synapse.commons.throttle.core.ThrottleWindowReplicator.java

public ThrottleWindowReplicator() {

    String replicatorThreads = System.getProperty(WINDOW_REPLICATOR_POOL_SIZE);

    if (replicatorThreads != null) {
        replicatorPoolSize = Integer.parseInt(replicatorThreads);
    }/*w w  w . j a v a  2  s.co m*/

    if (log.isDebugEnabled()) {
        log.debug("Throttle window replicator pool size set to " + replicatorPoolSize);
    }

    ScheduledExecutorService executor = Executors.newScheduledThreadPool(replicatorPoolSize,
            new ThreadFactory() {
                public Thread newThread(Runnable r) {
                    Thread t = new Thread(r);
                    t.setName("Throttle window replicator - " + replicatorCount++);
                    return t;
                }
            });

    String windowReplicationFrequency = System.getProperty(WINDOW_REPLICATOR_FREQUENCY);
    if (windowReplicationFrequency == null) {
        windowReplicationFrequency = "50";
    }

    if (log.isDebugEnabled()) {
        log.debug("Throttling window replication frequency set to " + windowReplicationFrequency);
    }

    for (int i = 0; i < replicatorPoolSize; i++) {
        executor.scheduleAtFixedRate(new ReplicatorTask(), Integer.parseInt(windowReplicationFrequency),
                Integer.parseInt(windowReplicationFrequency), TimeUnit.MILLISECONDS);
    }
}

From source file:org.micromanager.plugins.magellan.acq.AcqDurationEstimator.java

public AcqDurationEstimator() {
    executor_ = Executors.newSingleThreadExecutor(new ThreadFactory() {
        @Override//w w  w  . ja v  a  2 s.  co m
        public Thread newThread(Runnable r) {
            return new Thread(r, "Acquisition duration estimation Thread");
        }
    });

    //populate with one from preferences
    exposureMap_ = GlobalSettings.getObjectFromPrefs(GlobalSettings.getInstance().getGlobalPrefernces(),
            EXPOSURE_KEY, new TreeMap<Double, LinkedList<Double>>());
    xyMoveTimeList_ = GlobalSettings.getObjectFromPrefs(GlobalSettings.getInstance().getGlobalPrefernces(),
            XY_KEY, new LinkedList<Double>());
    zStepMoveTimeList_ = GlobalSettings.getObjectFromPrefs(GlobalSettings.getInstance().getGlobalPrefernces(),
            Z_KEY, new LinkedList<Double>());
    channelSwitchTimeList_ = GlobalSettings.getObjectFromPrefs(
            GlobalSettings.getInstance().getGlobalPrefernces(), CHANNEL_KEY, new LinkedList<Double>());

}

From source file:org.apache.hadoop.hbase.master.MasterMobCompactionThread.java

public MasterMobCompactionThread(HMaster master) {
    this.master = master;
    this.conf = master.getConfiguration();
    final String n = Thread.currentThread().getName();
    // this pool is used to run the mob compaction
    this.masterMobPool = new ThreadPoolExecutor(1, 2, 60, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),
            new ThreadFactory() {
                @Override//from  w ww .j av  a2 s  .  c o  m
                public Thread newThread(Runnable r) {
                    Thread t = new Thread(r);
                    t.setName(n + "-MasterMobCompaction-" + EnvironmentEdgeManager.currentTime());
                    return t;
                }
            });
    ((ThreadPoolExecutor) this.masterMobPool).allowCoreThreadTimeOut(true);
    // this pool is used in the mob compaction to compact the mob files by partitions
    // in parallel
    this.mobCompactorPool = MobUtils.createMobCompactorThreadPool(master.getConfiguration());
}

From source file:org.apache.hadoop.hbase.master.MasterMobFileCompactionThread.java

public MasterMobFileCompactionThread(HMaster master) {
    this.master = master;
    this.conf = master.getConfiguration();
    final String n = Thread.currentThread().getName();
    // this pool is used to run the mob file compaction
    this.masterMobPool = new ThreadPoolExecutor(1, 2, 60, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),
            new ThreadFactory() {
                @Override//from   w  w w  .j  a v  a 2 s.com
                public Thread newThread(Runnable r) {
                    Thread t = new Thread(r);
                    t.setName(n + "-MasterMobFileCompaction-" + EnvironmentEdgeManager.currentTime());
                    return t;
                }
            });
    ((ThreadPoolExecutor) this.masterMobPool).allowCoreThreadTimeOut(true);
    // this pool is used in the mob file compaction to compact the mob files by partitions
    // in parallel
    this.mobFileCompactorPool = MobUtils.createMobFileCompactorThreadPool(master.getConfiguration());
}

From source file:com.hellblazer.jackal.configuration.PartitionControllerConfig.java

protected ExecutorService controllerDispatchers() {
    final int id = partitionIdentity.id;
    return Executors.newCachedThreadPool(new ThreadFactory() {
        int count = 0;

        @Override/*from  w w  w  .ja va 2  s  .c  o m*/
        public Thread newThread(Runnable target) {
            Thread t = new Thread(target, String.format("Partition Controller Dispatcher[%s]", count++, id));
            t.setDaemon(true);
            t.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
                @Override
                public void uncaughtException(Thread t, Throwable e) {
                    log.error(String.format("Exception on %s", t), e);
                }
            });
            return t;
        }
    });
}

From source file:org.apache.asterix.experiment.client.SpatialQueryGenerator.java

public SpatialQueryGenerator(SpatialQueryGeneratorConfig config) {
    threadPool = Executors.newCachedThreadPool(new ThreadFactory() {

        private final AtomicInteger count = new AtomicInteger();

        @Override// w w w.  jav a  2 s . c o  m
        public Thread newThread(Runnable r) {
            int tid = count.getAndIncrement();
            Thread t = new Thread(r, "DataGeneratorThread: " + tid);
            t.setDaemon(true);
            return t;
        }
    });

    partitionRangeStart = config.getPartitionRangeStart();
    duration = config.getDuration();
    restHost = config.getRESTHost();
    restPort = config.getRESTPort();
    orchHost = config.getQueryOrchestratorHost();
    orchPort = config.getQueryOrchestratorPort();
    openStreetMapFilePath = config.getOpenStreetMapFilePath();
    isIndexOnlyPlan = config.getIsIndexOnlyPlan();
}

From source file:org.apache.phoenix.log.QueryLoggerDisruptor.java

public QueryLoggerDisruptor(Configuration configuration) throws SQLException {
    WaitStrategy waitStrategy;/*from  w w w . jav a2 s .  c o m*/
    try {
        waitStrategy = (WaitStrategy) Class
                .forName(configuration.get(QueryServices.LOG_BUFFER_WAIT_STRATEGY, DEFAULT_WAIT_STRATEGY))
                .newInstance();
    } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
        throw new SQLException(e);
    }

    ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("QueryLogger" + "-thread-%s")
            .setDaemon(true).setThreadFactory(new ThreadFactory() {
                @Override
                public Thread newThread(Runnable r) {
                    final Thread result = Executors.defaultThreadFactory().newThread(r);
                    result.setContextClassLoader(QueryLoggerDisruptor.class.getClass().getClassLoader());
                    return result;
                }
            }).build();
    disruptor = new Disruptor<RingBufferEvent>(RingBufferEvent.FACTORY,
            configuration.getInt(QueryServices.LOG_BUFFER_SIZE, RING_BUFFER_SIZE), threadFactory,
            ProducerType.MULTI, waitStrategy);
    final ExceptionHandler<RingBufferEvent> errorHandler = new QueryLoggerDefaultExceptionHandler();
    disruptor.setDefaultExceptionHandler(errorHandler);

    final QueryLogDetailsEventHandler[] handlers = { new QueryLogDetailsEventHandler(configuration) };
    disruptor.handleEventsWith(handlers);
    LOG.info("Starting  QueryLoggerDisruptor for with ringbufferSize="
            + disruptor.getRingBuffer().getBufferSize() + ", waitStrategy="
            + waitStrategy.getClass().getSimpleName() + ", " + "exceptionHandler=" + errorHandler + "...");
    disruptor.start();

}