List of usage examples for com.google.common.util.concurrent ThreadFactoryBuilder ThreadFactoryBuilder
public ThreadFactoryBuilder()
From source file:org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder.java
/** * @deprecated This method is only used from configuration modules and thus callers of it * should use service injection to make the executor configurable. *///from www. ja v a 2 s . com @Deprecated public static synchronized ListeningExecutorService getDefaultNotificationExecutor() { if (NOTIFICATION_EXECUTOR == null) { int queueSize = MAX_NOTIFICATION_QUEUE_SIZE; final String queueValue = System.getProperty(NOTIFICATION_QUEUE_SIZE_PROPERTY); if (StringUtils.isNotBlank(queueValue)) { try { queueSize = Integer.parseInt(queueValue); logger.trace("Queue size was set to {}", queueSize); } catch (final NumberFormatException e) { logger.warn("Cannot parse {} as set by {}, using default {}", queueValue, NOTIFICATION_QUEUE_SIZE_PROPERTY, queueSize); } } // Overriding the queue: // ThreadPoolExecutor would not create new threads if the queue is not full, thus adding // occurs in RejectedExecutionHandler. // This impl saturates threadpool first, then queue. When both are full caller will get blocked. final BlockingQueue<Runnable> delegate = new LinkedBlockingQueue<>(queueSize); final BlockingQueue<Runnable> queue = new ForwardingBlockingQueue<Runnable>() { @Override protected BlockingQueue<Runnable> delegate() { return delegate; } @Override public boolean offer(final Runnable r) { // ThreadPoolExecutor will spawn a new thread after core size is reached only // if the queue.offer returns false. return false; } }; final ThreadFactory factory = new ThreadFactoryBuilder().setDaemon(true) .setNameFormat("md-sal-binding-notification-%d").build(); final ThreadPoolExecutor executor = new ThreadPoolExecutor(CORE_NOTIFICATION_THREADS, MAX_NOTIFICATION_THREADS, NOTIFICATION_THREAD_LIFE, TimeUnit.SECONDS, queue, factory, new RejectedExecutionHandler() { // if the max threads are met, then it will raise a rejectedExecution. We then push to the queue. @Override public void rejectedExecution(final Runnable r, final ThreadPoolExecutor executor) { try { executor.getQueue().put(r); } catch (final InterruptedException e) { throw new RejectedExecutionException("Interrupted while waiting on the queue", e); } } }); NOTIFICATION_EXECUTOR = MoreExecutors.listeningDecorator(executor); } return NOTIFICATION_EXECUTOR; }
From source file:org.apache.omid.tso.ReplyProcessorImpl.java
@Inject ReplyProcessorImpl(MetricsRegistry metrics, Panicker panicker, ObjectPool<Batch> batchPool) { // ------------------------------------------------------------------------------------------------------------ // Disruptor initialization // ------------------------------------------------------------------------------------------------------------ ThreadFactoryBuilder threadFactory = new ThreadFactoryBuilder().setNameFormat("reply-%d"); this.disruptorExec = Executors.newSingleThreadExecutor(threadFactory.build()); this.disruptor = new Disruptor<>(EVENT_FACTORY, 1 << 12, disruptorExec, MULTI, new BusySpinWaitStrategy()); disruptor.handleExceptionsWith(new FatalExceptionHandler(panicker)); disruptor.handleEventsWith(this); this.replyRing = disruptor.start(); // ------------------------------------------------------------------------------------------------------------ // Attribute initialization // ------------------------------------------------------------------------------------------------------------ this.batchPool = batchPool; this.nextIDToHandle.set(0); this.futureEvents = new PriorityQueue<>(10, new Comparator<ReplyBatchEvent>() { public int compare(ReplyBatchEvent replyBatchEvent1, ReplyBatchEvent replyBatchEvent2) { return Long.compare(replyBatchEvent1.getBatchSequence(), replyBatchEvent2.getBatchSequence()); }//ww w. j a va 2 s.com }); // Metrics config this.abortMeter = metrics.meter(name("tso", "aborts")); this.commitMeter = metrics.meter(name("tso", "commits")); this.timestampMeter = metrics.meter(name("tso", "timestampAllocation")); LOG.info("ReplyProcessor initialized"); }
From source file:org.apache.s4.comm.staging.ThrottlingThreadPoolExecutorService.java
/** * /* w w w. j ava 2 s .c o m*/ * @param parallelism * Maximum number of threads in the pool * @param threadName * Naming scheme * @param workQueueSize * Queue capacity * @param classLoader * ClassLoader used as contextClassLoader for spawned threads */ public ThrottlingThreadPoolExecutorService(int parallelism, int rate, String threadName, int workQueueSize, final ClassLoader classLoader) { super(); this.parallelism = parallelism; this.streamName = threadName; this.classLoader = classLoader; this.workQueueSize = workQueueSize; this.droppingMeter = Metrics.newMeter(getClass(), "throttling-dropping", "throttling-dropping", TimeUnit.SECONDS); ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true).setNameFormat(threadName) .setThreadFactory(new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setContextClassLoader(classLoader); return t; } }).build(); rateLimitedPermits = RateLimiter.create(rate); workQueue = new ArrayBlockingQueue<Runnable>(workQueueSize + parallelism); ThreadPoolExecutor eventProcessingExecutor = new ThreadPoolExecutor(parallelism, parallelism, 60, TimeUnit.SECONDS, workQueue, threadFactory, new RejectedExecutionHandler() { @Override public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { droppingMeter.mark(); } }); eventProcessingExecutor.allowCoreThreadTimeOut(true); executorDelegatee = MoreExecutors.listeningDecorator(eventProcessingExecutor); }
From source file:com.jordanwilliams.heftydb.write.TableWriter.java
public TableWriter(Config config, Paths paths, Tables tables, Snapshots snapshots, Caches caches, Metrics metrics) {/* ww w .ja va 2 s.c om*/ this.config = config; this.paths = paths; this.tables = tables; this.snapshots = snapshots; this.caches = caches; this.metrics = metrics; this.writeThrottle = new Throttle(config.maxWriteRate()); this.tableExecutor = new ThreadPoolExecutor(config.tableWriterThreads(), config.tableWriterThreads(), Long.MAX_VALUE, TimeUnit.DAYS, new LinkedBlockingQueue<Runnable>(config.tableWriterThreads()), new ThreadFactoryBuilder().setNameFormat("Table writer thread %d").build(), new ThreadPoolExecutor.CallerRunsPolicy()); }
From source file:org.apache.tez.common.ProgressHelper.java
public void scheduleProgressTaskService(long delay, long period) { scheduledExecutorService = Executors.newScheduledThreadPool(1, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("TaskProgressService{" + processorName + ":" + processorContext.getTaskVertexName() + "} #%d").build()); scheduledExecutorService.scheduleWithFixedDelay(monitorProgress, delay, period, TimeUnit.MILLISECONDS); }
From source file:com.kuaidadi.ErrorAnalyzeAvroSourceTool.java
private NioServerSocketChannelFactory initSocketChannelFactory() { NioServerSocketChannelFactory socketChannelFactory; if (maxThreads <= 0) { socketChannelFactory = new NioServerSocketChannelFactory( Executors.newCachedThreadPool(new ThreadFactoryBuilder() .setNameFormat("Avro " + NettyTransceiver.class.getSimpleName() + " Boss-%d").build()), Executors.newCachedThreadPool(new ThreadFactoryBuilder() .setNameFormat("Avro " + NettyTransceiver.class.getSimpleName() + " I/O Worker-%d") .build()));//from www. j a v a2 s .co m } else { socketChannelFactory = new NioServerSocketChannelFactory( Executors.newCachedThreadPool(new ThreadFactoryBuilder() .setNameFormat("Avro " + NettyTransceiver.class.getSimpleName() + " Boss-%d").build()), Executors.newFixedThreadPool(maxThreads, new ThreadFactoryBuilder().setNameFormat( "" + "" + "" + " " + NettyTransceiver.class.getSimpleName() + " I/O Worker-%d") .build())); } return socketChannelFactory; }
From source file:com.alibaba.wasp.master.BulkAssigner.java
/** * Run the bulk assign./*from www. j av a2 s .co m*/ * * @param sync * Whether to assign synchronously. * @throws InterruptedException * @return True if done. * @throws java.io.IOException */ public boolean bulkAssign(boolean sync) throws InterruptedException, IOException { boolean result = false; ThreadFactoryBuilder builder = new ThreadFactoryBuilder(); builder.setDaemon(true); builder.setNameFormat(getThreadNamePrefix() + "-%1$d"); builder.setUncaughtExceptionHandler(getUncaughtExceptionHandler()); int threadCount = getThreadCount(); java.util.concurrent.ExecutorService pool = Executors.newFixedThreadPool(threadCount, builder.build()); try { populatePool(pool); // How long to wait on empty entityGroups-in-transition. If we timeout, the // RIT monitor should do fixup. if (sync) result = waitUntilDone(getTimeoutOnRIT()); } finally { // We're done with the pool. It'll exit when its done all in queue. pool.shutdown(); } return result; }
From source file:org.excalibur.core.compute.monitoring.monitors.InstanceStateMonitor.java
public InstanceStateMonitor(InstanceService instanceService, ProviderRepository providerRepository, UserRepository userRepository) { this.instanceService_ = instanceService; this.providerRepository_ = providerRepository; this.userRepository_ = userRepository; ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("instance-state-monitor-%d").build(); executor = DynamicExecutors.newListeningDynamicScalingThreadPool(1, 100, 1, TimeUnit.MINUTES, threadFactory);/*from ww w. j a v a 2s .co m*/ }
From source file:org.apache.hadoop.hbase.master.BulkAssigner.java
/** * Run the bulk assign./*from w w w .j a v a 2s. c o m*/ * * @param sync * Whether to assign synchronously. * @throws InterruptedException * @return True if done. * @throws IOException */ public boolean bulkAssign(boolean sync) throws InterruptedException, IOException { boolean result = false; ThreadFactoryBuilder builder = new ThreadFactoryBuilder(); builder.setDaemon(true); builder.setNameFormat(getThreadNamePrefix() + "-%1$d"); builder.setUncaughtExceptionHandler(getUncaughtExceptionHandler()); int threadCount = getThreadCount(); java.util.concurrent.ExecutorService pool = Executors.newFixedThreadPool(threadCount, builder.build()); try { populatePool(pool); // How long to wait on empty regions-in-transition. If we timeout, the // RIT monitor should do fixup. if (sync) result = waitUntilDone(getTimeoutOnRIT()); } finally { // We're done with the pool. It'll exit when its done all in queue. pool.shutdown(); } return result; }
From source file:org.apache.tez.dag.app.dag.RootInputInitializerRunner.java
@SuppressWarnings("rawtypes") public RootInputInitializerRunner(String dagName, String vertexName, TezVertexID vertexID, EventHandler eventHandler, UserGroupInformation dagUgi, int numTasks) { this.dagName = dagName; this.vertexName = vertexName; this.vertexID = vertexID; this.eventHandler = eventHandler; this.numTasks = numTasks; this.rawExecutor = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true) .setNameFormat("InputInitializer [" + this.vertexName + "] #%d").build()); this.executor = MoreExecutors.listeningDecorator(rawExecutor); this.dagUgi = dagUgi; }