List of usage examples for com.google.common.util.concurrent ThreadFactoryBuilder ThreadFactoryBuilder
public ThreadFactoryBuilder()
From source file:com.netflix.metacat.thrift.AbstractThriftServer.java
/** * Server initialization.// w w w.j a v a2s . com * @throws Exception error */ public void start() throws Exception { log.info("initializing thrift server {}", getServerName()); final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat(threadPoolNameFormat) .setUncaughtExceptionHandler((t, e) -> log.error("Uncaught exception in thread: " + t.getName(), e)) .build(); final ExecutorService executorService = new ThreadPoolExecutor( Math.min(2, config.getThriftServerMaxWorkerThreads()), config.getThriftServerMaxWorkerThreads(), 60L, TimeUnit.SECONDS, new SynchronousQueue<>(), threadFactory); final int timeout = config.getThriftServerSocketClientTimeoutInSeconds() * 1000; final TServerTransport serverTransport = new TServerSocket(portNumber, timeout); startServing(executorService, serverTransport); }
From source file:org.apache.omid.tso.client.TSOClientRaw.java
public TSOClientRaw(String host, int port) throws InterruptedException, ExecutionException { // Start client with Nb of active threads = 3 as maximum. ChannelFactory factory = new NioClientSocketChannelFactory( Executors//from w ww . j a va 2 s.com .newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("tsoclient-boss-%d").build()), Executors.newCachedThreadPool( new ThreadFactoryBuilder().setNameFormat("tsoclient-worker-%d").build()), 3); // Create the bootstrap ClientBootstrap bootstrap = new ClientBootstrap(factory); InetSocketAddress addr = new InetSocketAddress(host, port); ChannelPipeline pipeline = bootstrap.getPipeline(); pipeline.addLast("lengthbaseddecoder", new LengthFieldBasedFrameDecoder(8 * 1024, 0, 4, 0, 4)); pipeline.addLast("lengthprepender", new LengthFieldPrepender(4)); pipeline.addLast("protobufdecoder", new ProtobufDecoder(TSOProto.Response.getDefaultInstance())); pipeline.addLast("protobufencoder", new ProtobufEncoder()); Handler handler = new Handler(); pipeline.addLast("handler", handler); bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("keepAlive", true); bootstrap.setOption("reuseAddress", true); bootstrap.setOption("connectTimeoutMillis", 100); ChannelFuture channelFuture = bootstrap.connect(addr).await(); channel = channelFuture.getChannel(); }
From source file:org.opendaylight.ovsdb.hwvtepsouthbound.reconciliation.ReconciliationManager.java
public ReconciliationManager(final DataBroker db) { this.db = db; reconcilers = SpecialExecutors.newBoundedCachedThreadPool(NO_OF_RECONCILER, RECON_TASK_QUEUE_SIZE, "ovsdb-reconciler"); ThreadFactory threadFact = new ThreadFactoryBuilder().setNameFormat("ovsdb-recon-task-triager-%d").build(); taskTriager = Executors.newSingleThreadScheduledExecutor(threadFact); }
From source file:io.tilt.minka.spectator.PublishSubscribeQueue.java
protected PublishSubscribeQueue(final String name, final Consumer<MessageMetadata> consumer, final long retentionMs, final CuratorFramework client, final String logId) { this.name = name; this.userListener = consumer; this.retentionMs = retentionMs; this.client = client; this.logId = logId; this.retentionExecutor = Executors.newSingleThreadScheduledExecutor( new ThreadFactoryBuilder().setNameFormat("SPECTATOR-Queues-Retainer").build()); start(retentionMs);// w ww .j a v a2 s.c o m }
From source file:de.ks.flatadocdb.index.GlobalIndex.java
public GlobalIndex(Repository repository, MetaModel metaModel) { this(repository, metaModel, Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setDaemon(true).build())); }
From source file:com.github.autermann.wps.streaming.ProcessConfiguration.java
public ExecutorService createThreadPool() { String nameFormat = "streaming-process-" + getProcessID() + "-%d"; ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat(nameFormat).build(); return Executors.newCachedThreadPool(threadFactory); }
From source file:org.apache.tajo.worker.TaskRunner.java
public TaskRunner(ExecutionBlockContext executionBlockContext, String containerId) { super(TaskRunner.class.getName()); ThreadFactoryBuilder builder = new ThreadFactoryBuilder(); ThreadFactory fetcherFactory = builder.setNameFormat("Fetcher executor #%d").build(); this.systemConf = executionBlockContext.getConf(); this.fetchLauncher = Executors.newFixedThreadPool( systemConf.getIntVar(ConfVars.SHUFFLE_FETCHER_PARALLEL_EXECUTION_MAX_NUM), fetcherFactory); try {//from w ww . java 2 s . com this.containerId = TajoConverterUtils.toTajoContainerId(containerId); this.executionBlockContext = executionBlockContext; this.history = executionBlockContext.createTaskRunnerHistory(this); this.history.setState(getServiceState()); } catch (Exception e) { LOG.error(e.getMessage(), e); } }
From source file:fr.inria.eventcloud.overlay.SemanticRequestResponseManager.java
public SemanticRequestResponseManager(TransactionalTdbDatastore colanderDatastore) { super();//from ww w .j a va2s. c om this.colander = new SparqlColander(colanderDatastore); this.pendingResults = new ConcurrentHashMap<MessageId, Future<? extends Object>>(16, 0.75f, P2PStructuredProperties.MAO_LIMIT_PEERS.getValue()); this.threadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), new ThreadFactoryBuilder().setNameFormat(this.getClass().getSimpleName() + "-pool-thread-%d") .build()); }
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/* w w w . j a v a 2 s.c o 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:com.dmdirc.util.LoggingScheduledExecutorService.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 afterExecute The function to call when an exception occurs * @param poolName The naming format to use when naming threads */// w w w. j ava 2s. c o m public LoggingScheduledExecutorService(final int coreSize, final BiConsumer<Runnable, Throwable> afterExecute, final String poolName) { super(coreSize, new ThreadFactoryBuilder().setNameFormat(poolName + "-%d").build()); this.afterExecute = afterExecute; }