List of usage examples for com.google.common.util.concurrent ThreadFactoryBuilder ThreadFactoryBuilder
public ThreadFactoryBuilder()
From source file:org.apache.bookkeeper.clients.utils.ClientResources.java
private ClientResources() { this.scheduler = new Resource<OrderedScheduler>() { private static final String name = "client-scheduler"; @Override/*from www . j a v a 2 s. com*/ public OrderedScheduler create() { return OrderedScheduler.newSchedulerBuilder() .numThreads(Runtime.getRuntime().availableProcessors() * 2).name(name).build(); } @Override public void close(OrderedScheduler instance) { instance.shutdown(); } @Override public String toString() { return name; } }; this.timer = new Resource<HashedWheelTimer>() { private static final String name = "client-timer"; @Override public HashedWheelTimer create() { HashedWheelTimer timer = new HashedWheelTimer( new ThreadFactoryBuilder().setNameFormat(name + "-%d").build(), 200, TimeUnit.MILLISECONDS, 512, true); timer.start(); return timer; } @Override public void close(HashedWheelTimer instance) { instance.stop(); } @Override public String toString() { return name; } }; this.executor = new Resource<ExecutorService>() { private static final String name = "stream-client-executor"; @Override public ExecutorService create() { return Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2); } @Override public void close(ExecutorService instance) { instance.shutdown(); } @Override public String toString() { return name; } }; }
From source file:com.dragovorn.dragonbot.api.bot.plugin.BotPlugin.java
public ExecutorService getExecutorService() { if (this.executorService == null) { String name = (this.info == null) ? "unknown" : this.info.getName(); this.executorService = Executors .newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat(name + " Pool Thread #%1$d") .setThreadFactory(new GroupedThreadFactory(this, name)).build()); }//w w w .j av a2 s .c om return this.executorService; }
From source file:org.graylog2.radio.Radio.java
public Radio() { buffer = new Buffer(this); inputThreadPool = Executors/*from w w w . j a va2 s . co m*/ .newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("inputs-%d").build()); }
From source file:org.eclipse.che.plugin.maven.server.core.MavenClassPathBuilder.java
@Inject public MavenClassPathBuilder(ProjectManager projectManager, MavenClasspathContainerInitializer containerInitializer) { this.projectManager = projectManager; ThreadFactory threadFactory = new ThreadFactoryBuilder() .setNameFormat(MavenClassPathBuilder.class.getSimpleName() + "-%d").build(); executorService = Executors.newFixedThreadPool(5, threadFactory); }
From source file:com.cloudera.oryx.kmeans.computation.local.WeightedPointsByFold.java
@Override public List<List<WeightedRealVector>> call() throws InterruptedException, ExecutionException { Config config = ConfigUtils.getDefaultConfig(); ClusterSettings cluster = ClusterSettings.create(config); KSketchIndex index = buildIndex(foldVecs, cluster); int pointsPerIteration = cluster.getSketchPoints(); RandomGenerator random = RandomManager.getRandom(); ListeningExecutorService exec = MoreExecutors .listeningDecorator(Executors.newFixedThreadPool(config.getInt("model.parallelism"), new ThreadFactoryBuilder().setNameFormat("KSKETCH-%d").setDaemon(true).build())); for (int iter = 0; iter < cluster.getSketchIterations(); iter++) { log.info("Starting sketch iteration {}", iter + 1); List<ListenableFuture<Collection<RealVector>>> futures = Lists.newArrayList(); for (int foldId = 0; foldId < foldVecs.size(); foldId++) { futures.add(exec//w ww. j a va 2 s . c o m .submit(new SamplingRun(index, random, foldId, foldVecs.get(foldId), pointsPerIteration))); } // At the end of each iteration, gather up the sampled points to add to the index Future<List<Collection<RealVector>>> all = Futures.allAsList(futures); try { List<Collection<RealVector>> newSamples = all.get(); for (int foldId = 0; foldId < foldVecs.size(); foldId++) { for (RealVector v : newSamples.get(foldId)) { index.add(v, foldId); } } } catch (ExecutionException e) { ExecutorUtils.shutdownNowAndAwait(exec); all.cancel(true); throw e; } index.rebuildIndices(); } List<ListenableFuture<List<WeightedRealVector>>> ret = Lists.newArrayList(); for (int foldId = 0; foldId < foldVecs.size(); foldId++) { ret.add(exec.submit(new AssignmentRun(index, foldId, foldVecs.get(foldId)))); } try { return Futures.allAsList(ret).get(); } finally { ExecutorUtils.shutdownNowAndAwait(exec); } }
From source file:com.kolich.curacao.util.AsyncServletExecutorServiceFactory.java
public final ExecutorService build() { final ThreadFactoryBuilder builder = new ThreadFactoryBuilder(); if (threadNameFormat_ != null) { builder.setNameFormat(threadNameFormat_); }/*w w w .j ava 2 s. co 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:io.airlift.drift.transport.netty.ConnectionPool.java
public ConnectionPool(ConnectionManager connectionFactory, EventLoopGroup group, DriftNettyClientConfig config) { this.connectionFactory = connectionFactory; this.group = requireNonNull(group, "group is null"); requireNonNull(config, "config is null"); // todo from config cachedConnections = CacheBuilder.newBuilder().maximumSize(100).expireAfterAccess(10, TimeUnit.MINUTES) .<HostAndPort, Future<Channel>>removalListener( notification -> closeConnection(notification.getValue())) .build(new CacheLoader<HostAndPort, Future<Channel>>() { @Override//w w w . j a va 2 s . co m public Future<Channel> load(HostAndPort address) throws Exception { return createConnection(address); } }); maintenanceThread = newSingleThreadScheduledExecutor(new ThreadFactoryBuilder() .setNameFormat("drift-connection-maintenance-%s").setDaemon(true).build()); maintenanceThread.scheduleWithFixedDelay(cachedConnections::cleanUp, 1, 1, TimeUnit.SECONDS); }
From source file:org.apache.hadoop.io.ReadaheadPool.java
private ReadaheadPool() { pool = new ThreadPoolExecutor(POOL_SIZE, MAX_POOL_SIZE, 3L, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(CAPACITY)); pool.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardOldestPolicy()); pool.setThreadFactory(// w ww. j a v a2 s .co m new ThreadFactoryBuilder().setDaemon(true).setNameFormat("Readahead Thread #%d").build()); }
From source file:com.netflix.astyanax.connectionpool.impl.NodeDiscoveryImpl.java
public NodeDiscoveryImpl(String name, int interval, Supplier<List<Host>> hostSupplier, ConnectionPool<?> connectionPool) { this(name, interval, hostSupplier, connectionPool, Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setDaemon(true).build())); bOwnedExecutor = true;// w w w .j av a 2 s . c om }
From source file:com.cloudera.oryx.als.computation.local.MakeItemSimilarity.java
@Override public Object call() throws IOException { log.info("Starting item similarity"); Config config = ConfigUtils.getDefaultConfig(); final int howMany = config.getInt("model.item-similarity.how-many"); final LongPrimitiveIterator it = Y.keySetIterator(); final File similarItemsDir = new File(modelDir, "similarItems"); IOUtils.mkdirs(similarItemsDir);//from w ww.j a v a2 s . co m int numThreads = ExecutorUtils.getParallelism(); ExecutorService executor = Executors.newFixedThreadPool(numThreads, new ThreadFactoryBuilder().setNameFormat("ItemSimilarity-%d").setDaemon(true).build()); Collection<Future<Object>> futures = Lists.newArrayList(); try { for (int i = 0; i < numThreads; i++) { final int workerNumber = i; futures.add(executor.submit(new Callable<Object>() { @Override public Void call() throws IOException { Writer out = IOUtils.buildGZIPWriter(new File(similarItemsDir, workerNumber + ".csv.gz")); try { while (true) { long itemID; synchronized (it) { if (!it.hasNext()) { return null; } itemID = it.nextLong(); } float[] itemFeatures = Y.get(itemID); Iterable<NumericIDValue> mostSimilar = TopN.selectTopN( new MostSimilarItemIterator(Y.entrySet().iterator(), itemID, itemFeatures), howMany); String item1IDString = idMapping.toString(itemID); for (NumericIDValue similar : mostSimilar) { out.write(DelimitedDataUtils.encode(item1IDString, idMapping.toString(similar.getID()), Float.toString(similar.getValue()))); out.write('\n'); } } } finally { out.close(); } } })); } } finally { ExecutorUtils.shutdownNowAndAwait(executor); } ExecutorUtils.checkExceptions(futures); log.info("Finished item similarity"); return null; }