List of usage examples for com.google.common.util.concurrent ThreadFactoryBuilder setDaemon
public ThreadFactoryBuilder setDaemon(boolean daemon)
From source file:org.apache.hadoop.hbase.thrift2.ThriftServer.java
private static ExecutorService createExecutor(int workerThreads, ThriftMetrics metrics) { CallQueue callQueue = new CallQueue(new LinkedBlockingQueue<Call>(), metrics); ThreadFactoryBuilder tfb = new ThreadFactoryBuilder(); tfb.setDaemon(true); tfb.setNameFormat("thrift2-worker-%d"); return new ThreadPoolExecutor(workerThreads, workerThreads, Long.MAX_VALUE, TimeUnit.SECONDS, callQueue, tfb.build());/*ww w. j a v a 2s . c o m*/ }
From source file:talkeeg.common.ipc.IpcServiceImpl.java
IpcServiceImpl(IpcServiceManager serviceManager) { this.sm = serviceManager; final ThreadFactoryBuilder builder = new ThreadFactoryBuilder(); builder.setDaemon(true); builder.setNameFormat(getClass().getSimpleName() + "-pool-%d"); this.executor = Executors.newCachedThreadPool(builder.build()); this.messageProcessor = this.sm.messageProcessor; this.whirligig = new Whirligig(this.sm.config, this.sm.ioProcessor, this); }
From source file:com.alibaba.wasp.master.BulkAssigner.java
/** * Run the bulk assign.//from www .j a v a 2s. com * * @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.apache.hadoop.hbase.master.BulkAssigner.java
/** * Run the bulk assign./* w w w.j a va 2 s.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:talkeeg.common.core.DataService.java
@Inject DataService(IpcService ipc, ClientsAddressesService clientsAddresses) { this.ipc = ipc; this.clientsAddresses = clientsAddresses; IpcEntryHandler handler = new IpcEntryHandler() { @Override//from w w w .j a v a 2s. co m public void handle(IpcEntryHandlerContext context, IpcEntry entry) { if (!(entry instanceof Command)) { throw new RuntimeException("Unsupported IpcEntry type: " + entry); } processCommand(context, (Command) entry); } }; this.ipc.addIpcHandler(ACTION_DATA, handler); this.ipc.addIpcHandler(ACTION_DATA_RESPONSE, handler); final ThreadFactoryBuilder builder = new ThreadFactoryBuilder(); builder.setDaemon(true); builder.setNameFormat(getClass().getSimpleName() + "-pool-%d"); this.scheduledExecutorService = new ScheduledThreadPoolExecutor(1, builder.build()); }
From source file:talkeeg.common.core.PublicIpService.java
PublicIpService(Config config) { final String servicesString = config.getRoot().<String>getNode("net").getValue("publicIpServices", null); if (servicesString == null) { throw new NullPointerException( " 'net.publicIpServices' is null, but we need space delimited list of urls"); }/*w ww. jav a 2 s . com*/ this.knowedServices = Collections .unmodifiableList(StringUtils.splitTo(new ArrayList<String>(), servicesString, ' ')); final ThreadFactoryBuilder builder = new ThreadFactoryBuilder(); builder.setDaemon(true); builder.setNameFormat(getClass().getSimpleName() + "-pool-%d"); this.executor = Executors.newCachedThreadPool(builder.build()); reload(); }
From source file:org.apache.hadoop.hbase.thrift.TBoundedThreadPoolServer.java
public TBoundedThreadPoolServer(Args options, ThriftMetrics metrics) { super(options); if (options.maxQueuedRequests > 0) { this.callQueue = new CallQueue(new LinkedBlockingQueue<Call>(options.maxQueuedRequests), metrics); } else {/* w w w .j ava2s .c om*/ this.callQueue = new CallQueue(new SynchronousQueue<Call>(), metrics); } ThreadFactoryBuilder tfb = new ThreadFactoryBuilder(); tfb.setDaemon(true); tfb.setNameFormat("thrift-worker-%d"); executorService = new ThreadPoolExecutor(options.minWorkerThreads, options.maxWorkerThreads, options.threadKeepAliveTimeSec, TimeUnit.SECONDS, this.callQueue, tfb.build()); serverOptions = options; }
From source file:org.apache.phoenix.trace.TraceWriter.java
public void start() { traceSpanReceiver = getTraceSpanReceiver(); if (traceSpanReceiver == null) { LOG.warn("No receiver has been initialized for TraceWriter. Traces will not be written."); LOG.warn("Restart Phoenix to try again."); return;/*from www.j a v a 2 s . c o m*/ } ThreadFactoryBuilder builder = new ThreadFactoryBuilder(); builder.setDaemon(true).setNameFormat("PHOENIX-METRICS-WRITER"); executor = Executors.newScheduledThreadPool(this.numThreads, builder.build()); for (int i = 0; i < this.numThreads; i++) { executor.scheduleAtFixedRate(new FlushMetrics(), 0, 10, TimeUnit.SECONDS); } LOG.info("Writing tracing metrics to phoenix table"); }
From source file:com.kolich.curacao.util.AsyncServletExecutorServiceFactory.java
public final ExecutorService build() { final ThreadFactoryBuilder builder = new ThreadFactoryBuilder(); if (threadNameFormat_ != null) { builder.setNameFormat(threadNameFormat_); }/*from ww w . j a v a 2s .c o m*/ if (priority_ != null) { builder.setPriority(priority_); } if (useDaemon_ != null) { builder.setDaemon(useDaemon_); } return (size_ > 0) ? // Fixed sized thread pool (no more than N-threads). newFixedThreadPool(size_, builder.build()) : // Unbounded thread pool, will grow as needed. newCachedThreadPool(builder.build()); }
From source file:com.moz.fiji.commons.RefreshingReference.java
/** * Private constructor./*from w w w . j a v a 2 s. co m*/ * * @param refreshPeriod Configures the refresh rate for the scheduler. * @param timeUnit Specifies the unit of time for the refreshPeriod. * @param refreshingLoader Used to initialize and refresh the cached value. * @param builder Thread factory builder. Expects that the name format is already set. * @param loopController Used to deterministically control refresh cycles during testing. */ private RefreshingReference(final Long refreshPeriod, final TimeUnit timeUnit, final RefreshingLoader<T> refreshingLoader, final ThreadFactoryBuilder builder, final Optional<LoopController> loopController) { mRef = new AtomicReference<>(WithTimestamp.create(refreshingLoader.initial())); mScheduler = Executors.newSingleThreadScheduledExecutor(builder.setDaemon(true).build()); mRefreshingLoader = refreshingLoader; final RefreshingRunnable runnable = new RefreshingRunnable(); mScheduler.scheduleAtFixedRate(runnable, refreshPeriod, refreshPeriod, timeUnit); mLoopController = loopController; ResourceTracker.get().registerResource(this); }