List of usage examples for com.google.common.util.concurrent ThreadFactoryBuilder ThreadFactoryBuilder
public ThreadFactoryBuilder()
From source file:io.qdb.server.output.OutputManager.java
@Inject public OutputManager(EventBus eventBus, Repository repo, QueueManager queueManager, OutputHandlerFactory handlerFactory, MessageFilterFactory messageFilterFactory, JsonService jsonService) throws IOException { this.repo = repo; this.queueManager = queueManager; this.handlerFactory = handlerFactory; this.messageFilterFactory = messageFilterFactory; this.jsonService = jsonService; this.pool = new ThreadPoolExecutor(1, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new ThreadFactoryBuilder().setNameFormat("output-%d").setUncaughtExceptionHandler(this).build()); eventBus.register(this); for (Output output : this.repo.findOutputs(0, -1)) outputChanged(output);/*from w w w .j a v a 2 s .c o m*/ }
From source file:com.cinchapi.concourse.server.concurrent.ConcourseExecutors.java
/** * Return a thread factory that will name all threads using * {@code threadNamePrefix}./* w w w. j av a2 s . c o m*/ * * @param threadNamePrefix * @return the thread factory */ private static ThreadFactory getThreadFactory(String threadNamePrefix) { return new ThreadFactoryBuilder().setNameFormat(threadNamePrefix + " #%d") .setUncaughtExceptionHandler(uncaughtExceptionHandler).build(); }
From source file:com.metamx.druid.realtime.firehose.GracefulShutdownFirehose.java
public GracefulShutdownFirehose(Firehose firehose, IndexGranularity segmentGranularity, Period windowPeriod) { this.firehose = firehose; this.segmentGranularity = segmentGranularity; this.windowMillis = windowPeriod.toStandardDuration().getMillis() * 2; this.scheduledExecutor = Executors.newScheduledThreadPool(1, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("firehose_scheduled_%d").build()); final long truncatedNow = segmentGranularity.truncate(new DateTime()).getMillis(); final long end = segmentGranularity.increment(truncatedNow); this.rejectionPolicy = new IntervalRejectionPolicyFactory(new Interval(truncatedNow, end)) .create(windowPeriod);/*w ww. j a v a 2 s .co m*/ }
From source file:kafka.mirrormaker.TopicPartitionCountObserver.java
public TopicPartitionCountObserver(final String zkConnect, final String zkPath, final int zkConnectionTimeoutMs, final int zkSessionTimeoutMs, final int refreshIntervalMs) { logger.info("Init TopicPartitionCountObserver for zkConnect={} and zkPath={}", zkConnect, zkPath); this.zkConnect = zkConnect; this.zkPath = zkPath; zkClient = new ZkClient(zkConnect, zkSessionTimeoutMs, zkConnectionTimeoutMs, ZKStringSerializer$.MODULE$); zkUtils = ZkUtils.apply(zkClient, false); this.refreshIntervalMs = refreshIntervalMs; cronExecutor = Executors.newSingleThreadScheduledExecutor( new ThreadFactoryBuilder().setNameFormat("topic-observer-%d").build()); }
From source file:com.google.devtools.build.lib.concurrent.ExecutorShutdownUtil.java
/** * Create a "slack" thread pool which has the following properties: * 1. the worker count shrinks as the threads go unused * 2. the rejection policy is caller-runs * * @param threads maximum number of threads in the pool * @param name name of the pool//from w w w . j a v a2 s . co m * @return the new ThreadPoolExecutor */ public static ThreadPoolExecutor newSlackPool(int threads, String name) { // Using a synchronous queue with a bounded thread pool means we'll reject // tasks after the pool size. The CallerRunsPolicy, however, implies that // saturation is handled in the calling thread. ThreadPoolExecutor pool = new ThreadPoolExecutor(threads, threads, 3L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>()); // Do not consume threads when not in use. pool.allowCoreThreadTimeOut(true); pool.setThreadFactory(new ThreadFactoryBuilder().setNameFormat(name + " %d").build()); pool.setRejectedExecutionHandler(new RejectedExecutionHandler() { @Override public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { r.run(); } }); return pool; }
From source file:com.metamx.rdiclient.kafka.KafkaRdiConsumer.java
public KafkaRdiConsumer(final ConsumerConnector consumerConnector, final RdiClient<byte[]> rdiClient, final String topic, final int threads) { this.consumerConnector = consumerConnector; this.rdiClient = rdiClient; this.topic = topic; this.threads = threads; this.consumerExec = Executors.newFixedThreadPool(threads, new ThreadFactoryBuilder().setNameFormat("KafkaRdiConsumer-%d").setDaemon(true).build()); this.commitThread = new Thread(createCommitRunnable()); this.commitThread.setName("KafkaRdiConsumer-CommitThread"); this.commitThread.setDaemon(true); }
From source file:com.netflix.spinnaker.kork.astyanax.AstyanaxComponents.java
@Bean public ExecutorService cassandraAsyncExecutor( CassandraConfigurationProperties cassandraConfigurationProperties) { return Executors.newFixedThreadPool(cassandraConfigurationProperties.getAsyncExecutorPoolSize(), new ThreadFactoryBuilder().setDaemon(true).setNameFormat("AstyanaxAsync-%d").build()); }
From source file:natalia.dymnikova.util.ThreadPoolBeans.java
public ScheduledExecutorService commonPurposeScheduler0() { final ScheduledExecutorService scheduler = Executors .newScheduledThreadPool(10,//from ww w. j a v a 2 s . com new ThreadFactoryBuilder().setNameFormat("common-purpose-scheduler-%03d").setDaemon(true) .setUncaughtExceptionHandler( (t, e) -> log.debug("Uncaught exception in thread {}", t.getName(), e)) .build()); log.debug("Constructed common purpose scheduler {}", scheduler); return scheduler; }
From source file:jsondb.events.EventListenerList.java
public void addCollectionFileChangeListener(CollectionFileChangeListener listener) { if (null == listeners) { listeners = new ArrayList<CollectionFileChangeListener>(); listeners.add(listener);//from ww w . j a v a 2 s .co m collectionFilesWatcherExecutor = Executors.newSingleThreadExecutor( new ThreadFactoryBuilder().setNameFormat("jsondb-files-watcher-thread-%d").build()); try { watcher = dbConfig.getDbFilesPath().getFileSystem().newWatchService(); dbConfig.getDbFilesPath().register(watcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY); } catch (IOException e) { Logger.error("Failed to create the WatchService for the dbFiles location", e); throw new JsonDBException("Failed to create the WatchService for the dbFiles location", e); } collectionFilesWatcherExecutor.execute(new CollectionFilesWatcherRunnable()); } else { listeners.add(listener); } }
From source file:org.wso2.andes.kernel.slot.SlotDeletionExecutor.java
/** * Create slot deletion scheduler// w w w . jav a 2 s . co m */ public void init(int parallelTaskCount, int maxNumberOfPendingSlots) { this.numOfScheduledSlots = 0; this.parallelTaskCount = parallelTaskCount; this.slotDeletingTasks = new ArrayList<>(parallelTaskCount); // network partition detection works only when clustered. if (AndesContext.getInstance().isClusteringEnabled()) { AndesContext.getInstance().getClusterAgent().addNetworkPartitionListener(40, this); } ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("SlotDeletionExecutor-%d") .build(); this.slotDeletionExecutorService = Executors.newFixedThreadPool(parallelTaskCount, namedThreadFactory); for (int taskCount = 0; taskCount < parallelTaskCount; taskCount++) { SlotDeletingTask slotDeletingTask = new SlotDeletingTask(maxNumberOfPendingSlots); this.slotDeletingTasks.add(slotDeletingTask); this.slotDeletionExecutorService.submit(slotDeletingTask); } }