List of usage examples for com.google.common.util.concurrent ThreadFactoryBuilder ThreadFactoryBuilder
public ThreadFactoryBuilder()
From source file:org.roda.core.plugins.orchestrate.EmbeddedPluginOrchestrator.java
public EmbeddedPluginOrchestrator() { index = RodaCoreFactory.getIndexService(); model = RodaCoreFactory.getModelService(); storage = RodaCoreFactory.getStorageService(); final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("plugin-%d").setDaemon(true) .build();/*from w ww. j a v a 2s. co m*/ int threads = Runtime.getRuntime().availableProcessors() + 1; executorService = Executors.newFixedThreadPool(threads, threadFactory); LOGGER.debug("Running embedded plugin orchestrator on a {} thread pool", threads); }
From source file:org.apache.pig.backend.hadoop.ATSService.java
private ATSService() { synchronized (LOCK) { if (executor == null) { executor = Executors.newSingleThreadExecutor( new ThreadFactoryBuilder().setDaemon(true).setNameFormat("ATS Logger %d").build()); YarnConfiguration yarnConf = new YarnConfiguration(); timelineClient = TimelineClient.createTimelineClient(); timelineClient.init(yarnConf); timelineClient.start();/*from w w w. j a v a 2 s. com*/ } Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { timelineClient.stop(); executor.awaitTermination(WAIT_TIME, TimeUnit.SECONDS); executor = null; } catch (InterruptedException ie) { /* ignore */ } timelineClient.stop(); } }); } log.info("Created ATS Hook"); }
From source file:com.spotify.heroic.metric.bigtable.api.BigtableMutatorImpl.java
public BigtableMutatorImpl(AsyncFramework async, com.google.cloud.bigtable.grpc.BigtableSession session, boolean disableBulkMutations, int flushIntervalSeconds) { this.async = async; this.session = session; this.disableBulkMutations = disableBulkMutations; if (disableBulkMutations) { this.scheduler = null; this.tableToBulkMutation = null; } else {/*from w w w. jav a 2 s. co m*/ this.tableToBulkMutation = new HashMap<>(); this.scheduler = Executors.newScheduledThreadPool(1, new ThreadFactoryBuilder().setNameFormat("heroic-bigtable-flush").build()); scheduler.scheduleAtFixedRate(this::flush, 0, flushIntervalSeconds, TimeUnit.SECONDS); } }
From source file:org.excalibur.core.util.concurrent.DynamicExecutors.java
public static ListeningExecutorService newListeningDynamicScalingThreadPool(String threadNamesFormat, int max) { ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat(threadNamesFormat).build(); int max_ = max > getRuntime().availableProcessors() ? max : getRuntime().availableProcessors(); return newListeningDynamicScalingThreadPool(getRuntime().availableProcessors(), max_, 1, TimeUnit.MINUTES, threadFactory);//from w w w .ja va 2s . com }
From source file:org.apache.omid.tso.ProgrammableTSOServer.java
@Inject public ProgrammableTSOServer(int port) { // Setup netty listener factory = new NioServerSocketChannelFactory( Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("boss-%d").build()), Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("worker-%d").build()), (Runtime.getRuntime().availableProcessors() * 2 + 1) * 2); // Create the global ChannelGroup channelGroup = new DefaultChannelGroup(ProgrammableTSOServer.class.getName()); ServerBootstrap bootstrap = new ServerBootstrap(factory); bootstrap.setPipelineFactory(new TSOChannelHandler.TSOPipelineFactory(this)); // Add the parent channel to the group Channel channel = bootstrap.bind(new InetSocketAddress(port)); channelGroup.add(channel);//from w ww. ja v a 2 s . c o m LOG.info("********** Dumb TSO Server running on port {} **********", port); }
From source file:com.eclipsesource.connect.api.util.CallbackExecutorBuilder.java
private ThreadFactory createThreadFactory() { return new ThreadFactoryBuilder().setNameFormat(name + "-%d") .setUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override/* w ww . j a v a2s .co m*/ public void uncaughtException(Thread thread, Throwable throwable) { failureCallback.onFailure(throwable); } }).build(); }
From source file:org.apache.aurora.scheduler.base.AsyncUtil.java
/** * Creates a {@link ThreadPoolExecutor} that logs unhandled errors. * * @param corePoolSize see {@link ThreadPoolExecutor}. * @param maxPoolSize see {@link ThreadPoolExecutor}. * @param workQueue see {@link ThreadPoolExecutor}. * @param nameFormat Thread naming format. * @param logger Logger instance./*from w w w. j a v a 2 s .co m*/ * @return instance of {@link ThreadPoolExecutor} enabled to log unhandled exceptions. */ public static ThreadPoolExecutor loggingExecutor(int corePoolSize, int maxPoolSize, BlockingQueue<Runnable> workQueue, String nameFormat, final Logger logger) { return new ThreadPoolExecutor(corePoolSize, maxPoolSize, 0L, TimeUnit.MILLISECONDS, workQueue, new ThreadFactoryBuilder().setDaemon(true).setNameFormat(nameFormat).build()) { @Override protected void afterExecute(Runnable runnable, Throwable throwable) { super.afterExecute(runnable, throwable); evaluateResult(runnable, throwable, logger); } }; }
From source file:io.airlift.drift.transport.netty.DriftNettyMethodInvokerFactory.java
@Inject public DriftNettyMethodInvokerFactory(DriftNettyConnectionFactoryConfig factoryConfig, Function<I, DriftNettyClientConfig> clientConfigurationProvider) { requireNonNull(factoryConfig, "factoryConfig is null"); group = new NioEventLoopGroup(factoryConfig.getThreadCount(), new ThreadFactoryBuilder().setNameFormat("drift-client-%s").setDaemon(true).build()); this.clientConfigurationProvider = requireNonNull(clientConfigurationProvider, "clientConfigurationProvider is null"); }
From source file:org.apache.druid.emitter.opentsdb.OpentsdbSender.java
public OpentsdbSender(String host, int port, int connectionTimeout, int readTimeout, int flushThreshold, int maxQueueSize, long consumeDelay) { this.flushThreshold = flushThreshold; this.consumeDelay = consumeDelay; eventQueue = new ArrayBlockingQueue<>(maxQueueSize); scheduler = Executors.newScheduledThreadPool(2, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("OpentsdbEventSender-%s").build()); eventConsumer = new EventConsumer(); client = Client.create();/*from w w w . j a v a 2s.c om*/ client.setConnectTimeout(connectionTimeout); client.setReadTimeout(readTimeout); webResource = client.resource("http://" + host + ":" + port + PATH); }
From source file:org.excalibur.core.executor.task.SingleTaskExecutorService.java
public SingleTaskExecutorService() { ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("task-executor-%d") .setUncaughtExceptionHandler(new TaskUncaughtExceptionHandler()).build(); executor = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor(threadFactory)); }