List of usage examples for com.google.common.util.concurrent ThreadFactoryBuilder build
public ThreadFactory 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"); }/* www .ja va 2 s .c o m*/ 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.metaservice.kryo.ClientHandler.java
@Override public void received(final Connection connection, Object o) { if (o instanceof RegisterClientMessage) { RegisterClientMessage registerMessage = (RegisterClientMessage) o; LOGGER.info("registering... " + registerMessage); IndividualClientHandler individualClientHandler; switch (registerMessage.getType()) { case POSTPROCESS: individualClientHandler = new IndividualClientHandler<>( queueContainer.addPostProcessorQueue(registerMessage.getName()), registerMessage.getMessageCount()); break; case PROVIDER_CREATE: individualClientHandler = new IndividualClientHandler<>( queueContainer.addProviderCreateQueue(registerMessage.getName()), registerMessage.getMessageCount()); break; case PROVIDER_REFRESH: individualClientHandler = new IndividualClientHandler<>( queueContainer.addProviderRefreshQueue(registerMessage.getName()), registerMessage.getMessageCount()); break; default://from w w w . j ava 2 s .c o m LOGGER.warn("UNKNOWN TYPE " + registerMessage.getType()); return; } LOGGER.debug("on Connection {}", connection.getID()); ThreadFactoryBuilder builder = new ThreadFactoryBuilder() .setNameFormat("indivClient-" + registerMessage.getName() + "-%d"); listenerMap.put(connection.getID(), new Listener.ThreadedListener(individualClientHandler, Executors.newFixedThreadPool(1, builder.build()))); individualClientHandler.init(connection); } else { if (listenerMap.containsKey(connection.getID())) { listenerMap.get(connection.getID()).received(connection, o); } /*else{ //gets all write messages and keep alive messages LOGGER.warn("no listener to inform for message {}", o.getClass().getName()); }*/ } }
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()); }/*w w w . j a v a 2s.c o m*/ }); // 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.opendaylight.infrautils.utils.concurrent.ThreadFactoryProvider.java
@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED") // OK to ignore guavaBuilder.setPriority's return this in ifPresent() public ThreadFactory get() { ThreadFactoryBuilder guavaBuilder = new ThreadFactoryBuilder().setNameFormat(namePrefix() + "-%d") .setUncaughtExceptionHandler(LoggingThreadUncaughtExceptionHandler.toLogger(logger())) .setDaemon(daemon());//from w w w . j a v a 2 s.c om priority().ifPresent(guavaBuilder::setPriority); logger().info("ThreadFactory created: {}", namePrefix()); return guavaBuilder.build(); }
From source file:org.apache.omid.tso.PersistenceProcessorImpl.java
@Inject PersistenceProcessorImpl(TSOServerConfig config, CommitTable commitTable, ObjectPool<Batch> batchPool, Panicker panicker, PersistenceProcessorHandler[] handlers, MetricsRegistry metrics) throws Exception { // ------------------------------------------------------------------------------------------------------------ // Disruptor initialization // ------------------------------------------------------------------------------------------------------------ ThreadFactoryBuilder threadFactory = new ThreadFactoryBuilder().setNameFormat("persist-%d"); this.disruptorExec = Executors.newFixedThreadPool(config.getNumConcurrentCTWriters(), threadFactory.build()); this.disruptor = new Disruptor<>(EVENT_FACTORY, 1 << 20, disruptorExec, SINGLE, new BusySpinWaitStrategy()); disruptor.handleExceptionsWith(new FatalExceptionHandler(panicker)); // This must be before handleEventsWith() disruptor.handleEventsWithWorkerPool(handlers); this.persistRing = disruptor.start(); // ------------------------------------------------------------------------------------------------------------ // Attribute initialization // ------------------------------------------------------------------------------------------------------------ this.metrics = metrics; this.lowWatermarkWriter = commitTable.getWriter(); this.batchSequence = 0L; this.batchPool = batchPool; this.currentBatch = batchPool.borrowObject(); // Low Watermark writer ThreadFactoryBuilder lwmThreadFactory = new ThreadFactoryBuilder().setNameFormat("lwm-writer-%d"); this.lowWatermarkWriterExecutor = Executors.newSingleThreadExecutor(lwmThreadFactory.build()); // Metrics config this.lwmWriteTimer = metrics.timer(name("tso", "lwmWriter", "latency")); LOG.info("PersistentProcessor initialized"); }
From source file:net.myrrix.common.parallel.Paralleler.java
/** * Run {@link Processor}, in as many threads as available cores, on values. * /*from w w w. j av a 2 s.co m*/ * @throws ExecutionException if any execution fails */ public void runInParallel() throws InterruptedException, ExecutionException { ThreadFactoryBuilder builder = new ThreadFactoryBuilder(); if (name != null) { builder.setNameFormat(name + "-%s"); } int numCores = Runtime.getRuntime().availableProcessors(); ExecutorService executor = Executors.newFixedThreadPool(numCores, builder.build()); try { runInParallel(executor, numCores); } finally { executor.shutdownNow(); } }
From source file:com.kolich.boildown.Boil.java
private final void run() throws Exception { final Boiler.CompressionMethod method; final List<String> arguments; if (compress_ != null) { arguments = colonSplitter.splitToList(compress_); method = Boiler.CompressionMethod.COMPRESS; } else {//w w w .j a v a2 s . com arguments = colonSplitter.splitToList(decompress_); method = Boiler.CompressionMethod.DECOMPRESS; } if (arguments.size() != 3) { throw new IllegalArgumentException("Forwarder must be in the format of [port]:[host]:[port]"); } // Parse the arguments. final int listenPort = Integer.parseInt(arguments.get(0)); final String forwardHost = arguments.get(1); final int forwardPort = Integer.parseInt(arguments.get(2)); final Boiler.Strategery strategery = getStrategery(); final ThreadFactoryBuilder factoryBuilder = new ThreadFactoryBuilder().setDaemon(true) .setNameFormat("boiler-%d (" + listenPort + ":" + forwardHost + ":" + forwardPort + ")"); final ThreadPoolExecutor threadPool = (ThreadPoolExecutor) Executors.newFixedThreadPool(poolSize_, factoryBuilder.build()); try (final ServerSocket listener = new ServerSocket(listenPort)) { // Run loop! while (true) { // Blocks, waiting for new connections. final Socket client = listener.accept(); if (threadPool.getActiveCount() >= poolSize_) { // All boilers busy, forcibly hang up. IOUtils.closeQuietly(client); } else { // Submit the boiler to the pool, only if there's space to safely do so. threadPool .submit(new Boiler(client, method, strategery, forwardHost, forwardPort, bufferSize_)); } } } catch (Exception e) { log.error("Exception in main run-loop.", e); } finally { threadPool.shutdown(); } }
From source file:com.alibaba.wasp.master.BulkAssigner.java
/** * Run the bulk assign.// w w w. ja v a 2 s . c o 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.apache.hadoop.hbase.master.BulkAssigner.java
/** * Run the bulk assign.//ww w . j a v a 2 s .c om * * @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.bookkeeper.metastore.InMemoryMetastoreTable.java
public InMemoryMetastoreTable(InMemoryMetaStore metastore, String name) { this.map = new TreeMap<String, Versioned<Value>>(); this.watcherMap = new TreeMap<String, MetastoreWatcher>(); this.name = name; String thName = "InMemoryMetastore-Table(" + name + ")-Scheduler-%d"; ThreadFactoryBuilder tfb = new ThreadFactoryBuilder().setNameFormat(thName); this.scheduler = Executors.newSingleThreadScheduledExecutor(tfb.build()); }