List of usage examples for com.google.common.util.concurrent ThreadFactoryBuilder ThreadFactoryBuilder
public ThreadFactoryBuilder()
From source file:com.uber.stream.kafka.chaperone.collector.KafkaMonitor.java
public KafkaMonitor(long checkIntervalInSec, String brokerList, String auditTopics, IAuditReporter auditReporter) {/*from w ww.j av a2 s.c o m*/ this.checkIntervalInSec = checkIntervalInSec; this.brokerList = Arrays.asList(StringUtils.split(brokerList, ",")); this.auditTopics = Arrays.asList(StringUtils.split(auditTopics, ",")); this.auditReporter = auditReporter; this.brokerConsumer = new HashMap<>(); this.partitionLeader = new HashMap<>(); this.partitionLag = new ConcurrentHashMap<>(); this.partitionInjected = new HashSet<>(); cronExecutor = Executors.newSingleThreadScheduledExecutor( new ThreadFactoryBuilder().setNameFormat("kafka-monitor-%d").build()); }
From source file:org.apache.hadoop.yarn.server.sharedcachemanager.CleanerService.java
@Override protected void serviceInit(Configuration conf) throws Exception { this.conf = conf; // create scheduler executor service that services the cleaner tasks // use 2 threads to accommodate the on-demand tasks and reduce the chance of // back-to-back runs ThreadFactory tf = new ThreadFactoryBuilder().setNameFormat("Shared cache cleaner").build(); scheduledExecutor = Executors.newScheduledThreadPool(2, tf); super.serviceInit(conf); }
From source file:org.apache.tez.dag.app.launcher.TezLocalCacheManager.java
/** * Localize this instance's resources by downloading and symlinking them. * * @throws IOException when an error occurs in download or link *//*from w ww . j a v a 2s . co m*/ public void localize() throws IOException { String absPath = Paths.get(".").toAbsolutePath().normalize().toString(); Path cwd = fileContext.makeQualified(new Path(absPath)); ExecutorService threadPool = null; try { // construct new threads with helpful names ThreadFactory threadFactory = new ThreadFactoryBuilder() .setNameFormat("TezLocalCacheManager Downloader #%d").build(); threadPool = Executors.newCachedThreadPool(threadFactory); // start all fetches for (Map.Entry<String, LocalResource> entry : resources.entrySet()) { String resourceName = entry.getKey(); LocalResource resource = entry.getValue(); if (resource.getType() == LocalResourceType.PATTERN) { throw new IllegalArgumentException("Resource type PATTERN not supported."); } // linkPath is the path we want to symlink the file/directory into Path linkPath = new Path(cwd, entry.getKey()); if (resourceInfo.containsKey(resource)) { // We've already downloaded this resource and just need to add another link. resourceInfo.get(resource).linkPaths.add(linkPath); } else { // submit task to download the object java.nio.file.Path downloadDir = Files.createTempDirectory(tempDir, resourceName); Path dest = new Path(downloadDir.toAbsolutePath().toString()); FSDownload downloader = new FSDownload(fileContext, ugi, conf, dest, resource); Future<Path> downloadedPath = threadPool.submit(downloader); resourceInfo.put(resource, new ResourceInfo(downloadedPath, linkPath)); } } // Link each file for (Map.Entry<LocalResource, ResourceInfo> entry : resourceInfo.entrySet()) { LocalResource resource = entry.getKey(); ResourceInfo resourceMeta = entry.getValue(); for (Path linkPath : resourceMeta.linkPaths) { Path targetPath; try { // this blocks on the download completing targetPath = resourceMeta.downloadPath.get(); } catch (InterruptedException | ExecutionException e) { throw new IOException(e); } if (createSymlink(targetPath, linkPath)) { LOG.info("Localized file: {} as {}", resource, linkPath); } else { LOG.warn("Failed to create symlink: {} <- {}", targetPath, linkPath); } } } } finally { if (threadPool != null) { threadPool.shutdownNow(); } } }
From source file:lego.gracekelly.Kelly.java
/** * The Kelly constructor takes a {@link CacheProvider}, {@link CacheLoader}, a threadPool size * along with queueSize for cache reloading. * @param cacheProvider//from w w w .j a va2 s . c o m * @param cacheLoader * @param threadPoolSize max number of threads to be used for async refresh * @param queueSize max number of requests to be queued for async refresh */ public Kelly(CacheProvider<T> cacheProvider, CacheLoader<T> cacheLoader, int threadPoolSize, int queueSize) { this.cacheProvider = cacheProvider; this.cacheLoader = cacheLoader; executorService = new ThreadPoolExecutor(threadPoolSize, threadPoolSize, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(queueSize), new ThreadFactoryBuilder().setDaemon(false) .setNameFormat("fk-kelly-pool-%d").setPriority(Thread.NORM_PRIORITY).build()); this.requestsInFlight = new ConcurrentHashMap<String, Boolean>(); }
From source file:org.apache.druid.guice.DruidProcessingModule.java
@Provides @LazySingleton/*from ww w .j a v a2 s .c o m*/ public CachePopulator getCachePopulator(@Smile ObjectMapper smileMapper, CachePopulatorStats cachePopulatorStats, CacheConfig cacheConfig) { if (cacheConfig.getNumBackgroundThreads() > 0) { final ExecutorService exec = Executors.newFixedThreadPool(cacheConfig.getNumBackgroundThreads(), new ThreadFactoryBuilder().setNameFormat("background-cacher-%d").setDaemon(true) .setPriority(Thread.MIN_PRIORITY).build()); return new BackgroundCachePopulator(exec, smileMapper, cachePopulatorStats, cacheConfig.getMaxEntrySize()); } else { return new ForegroundCachePopulator(smileMapper, cachePopulatorStats, cacheConfig.getMaxEntrySize()); } }
From source file:org.wso2.carbon.event.processor.core.internal.storm.status.monitor.StormStatusMonitor.java
public StormStatusMonitor(int tenantId, String executionPlanName, int importedStreamsCount) throws DeploymentStatusMonitorException { if (EventProcessorValueHolder.getHazelcastInstance() == null) { throw new DeploymentStatusMonitorException( "Couldn't initialize Distributed Deployment Status monitor as" + " the hazelcast instance is null. Enable clustering and restart the server"); }//from www . ja v a 2 s .c o m executorService = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder() .setNameFormat("Thread pool- component - StormStatusMonitor.executorService;tenantId - " + tenantId + ";executionPlanName - " + executionPlanName) .build()); tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); connectedCepReceiversCount = new AtomicInteger(0); connectedPublisherBoltsCount = new AtomicInteger(0); try { hostIp = HostAddressFinder.findAddress("localhost"); } catch (SocketException e) { //do nothing. Let this be retried in the callbacks. } this.importedStreamsCount = importedStreamsCount; this.executionPlanName = executionPlanName; this.stormTopologyName = StormTopologyManager.getTopologyName(executionPlanName, tenantId); this.executionPlanStatusHolderKey = DistributedModeConstants.STORM_STATUS_MAP + "." + stormTopologyName; lockTimeout = EventProcessorValueHolder.getStormDeploymentConfiguration().getStatusLockTimeout(); executorService.execute(new GlobalStatUpdater()); }
From source file:org.glassfish.jersey.client.ClientAsyncExecutorsFactory.java
/** * Creates a new instance./*from www . j a v a2 s . c om*/ * * @param locator Injected HK2 service locator. */ public ClientAsyncExecutorsFactory(ServiceLocator locator) { super(locator); this.requestingExecutor = getInitialRequestingExecutor(new RequestExecutorsProvider() { @Override public ExecutorService getRequestingExecutor() { return Executors.newCachedThreadPool( new ThreadFactoryBuilder().setNameFormat("jersey-client-async-executor-%d").build()); } }); this.respondingExecutor = getInitialRespondingExecutor(new ResponseExecutorsProvider() { @Override public ExecutorService getRespondingExecutor() { return MoreExecutors.sameThreadExecutor(); } }); }
From source file:com.dmdirc.util.LoggingExecutorService.java
/** * Creates a new instance of this executor service. * * @param coreSize The number of threads to keep in the pool, even if they are idle, * unless {@code allowCoreThreadTimeOut} is set * @param maxSize The maximum number of threads to allow in the pool * @param afterExecute The function to call when an exception occurs * @param poolName The naming format to use when naming threads *//*from ww w . ja v a2 s. c om*/ public LoggingExecutorService(final int coreSize, final int maxSize, final BiConsumer<Runnable, Throwable> afterExecute, final String poolName) { super(coreSize, maxSize, 0, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(5)); this.afterExecute = afterExecute; setThreadFactory(new ThreadFactoryBuilder().setNameFormat(poolName + "-%d").build()); }
From source file:org.eclipse.hawkbit.autoconfigure.scheduling.ExecutorAutoConfiguration.java
/** * @return central ThreadPoolExecutor for general purpose multi threaded * operations. Tries an orderly shutdown when destroyed. *//* w w w . java 2 s . c o m*/ private ThreadPoolExecutor threadPoolExecutor() { final BlockingQueue<Runnable> blockingQueue = new ArrayBlockingQueue<>( asyncConfigurerProperties.getQueuesize()); return new ThreadPoolExecutor(asyncConfigurerProperties.getCorethreads(), asyncConfigurerProperties.getMaxthreads(), asyncConfigurerProperties.getIdletimeout(), TimeUnit.MILLISECONDS, blockingQueue, new ThreadFactoryBuilder().setNameFormat("central-executor-pool-%d").build(), new PoolSizeExceededPolicy()); }
From source file:com.nesscomputing.cache.MemcachedClientFactory.java
@OnStage(LifecycleStage.START) public void start() { Preconditions.checkState(clientReconfigurationService.get() == null, "client is already started!"); final ThreadFactory tf = new ThreadFactoryBuilder().setNameFormat("memcached-discovery-" + cacheName) .setDaemon(true).build();//from w w w. ja v a2 s. co m final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1, tf); if (clientReconfigurationService.compareAndSet(null, executor)) { LOG.info("Kicking off memcache topology discovery thread"); final MemcachedDiscoveryUpdate updater = new MemcachedDiscoveryUpdate(); // Run update once before anything else happens so we don't // observe a null client after the lifecycle starts updater.run(); final long rediscoveryInterval = configuration.getCacheServerRediscoveryInterval().getMillis(); executor.scheduleAtFixedRate(updater, rediscoveryInterval, rediscoveryInterval, TimeUnit.MILLISECONDS); } else { LOG.warn("Race condition while starting discovery thread!"); executor.shutdown(); } }