List of usage examples for com.google.common.util.concurrent ThreadFactoryBuilder setNameFormat
public ThreadFactoryBuilder setNameFormat(String nameFormat)
From source file:org.metaservice.kryo.IndividualClientHandler.java
public IndividualClientHandler(Queue<T> queue, int flightCount) { ThreadFactoryBuilder builder = new ThreadFactoryBuilder().setDaemon(true) .setNameFormat(queue.getName() + "-sumit-%d"); submitExecutorService = Executors.newSingleThreadExecutor(builder.build()); builder.setNameFormat(queue.getName() + "-response-%d"); responseExecutorService = Executors.newSingleThreadExecutor(builder.build()); this.queue = queue; this.flightCount = flightCount; }
From source file:org.opendaylight.vpnservice.interfacemgr.pmcounters.NodeConnectorStatsImpl.java
private ThreadFactory getThreadFactory(String threadNameFormat) { ThreadFactoryBuilder builder = new ThreadFactoryBuilder(); builder.setNameFormat(threadNameFormat); builder.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override/*from w w w . ja va 2 s . c o m*/ public void uncaughtException(Thread t, Throwable e) { logger.error("Received Uncaught Exception event in Thread: {}", t.getName(), e); } }); return builder.build(); }
From source file:org.opendaylight.genius.interfacemanager.pmcounters.NodeConnectorStatsImpl.java
private ThreadFactory getThreadFactory(String threadNameFormat) { ThreadFactoryBuilder builder = new ThreadFactoryBuilder(); builder.setNameFormat(threadNameFormat); builder.setUncaughtExceptionHandler((thread, exception) -> LOG .error("Received Uncaught Exception event in Thread: {}", thread.getName(), exception)); return builder.build(); }
From source file:org.apache.hadoop.hbase.thrift.TBoundedThreadPoolServer.java
public TBoundedThreadPoolServer(Args options, ThriftMetrics metrics) { super(options); if (options.maxQueuedRequests > 0) { this.callQueue = new CallQueue(new LinkedBlockingQueue<Call>(options.maxQueuedRequests), metrics); } else {// w w w. ja va 2 s . c o m this.callQueue = new CallQueue(new SynchronousQueue<Call>(), metrics); } ThreadFactoryBuilder tfb = new ThreadFactoryBuilder(); tfb.setDaemon(true); tfb.setNameFormat("thrift-worker-%d"); executorService = new ThreadPoolExecutor(options.minWorkerThreads, options.maxWorkerThreads, options.threadKeepAliveTimeSec, TimeUnit.SECONDS, this.callQueue, tfb.build()); serverOptions = options; }
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 {// w w w .java2 s . co m 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:org.apache.hadoop.hbase.replication.regionserver.HFileReplicator.java
public HFileReplicator(Configuration sourceClusterConf, String sourceBaseNamespaceDirPath, String sourceHFileArchiveDirPath, Map<String, List<Pair<byte[], List<String>>>> tableQueueMap, Configuration conf, Connection connection) throws IOException { this.sourceClusterConf = sourceClusterConf; this.sourceBaseNamespaceDirPath = sourceBaseNamespaceDirPath; this.sourceHFileArchiveDirPath = sourceHFileArchiveDirPath; this.bulkLoadHFileMap = tableQueueMap; this.conf = conf; this.connection = connection; userProvider = UserProvider.instantiate(conf); fsDelegationToken = new FsDelegationToken(userProvider, "renewer"); this.hbaseStagingDir = conf.get("hbase.bulkload.staging.dir"); this.maxCopyThreads = this.conf.getInt(REPLICATION_BULKLOAD_COPY_MAXTHREADS_KEY, REPLICATION_BULKLOAD_COPY_MAXTHREADS_DEFAULT); ThreadFactoryBuilder builder = new ThreadFactoryBuilder(); builder.setNameFormat("HFileReplicationCallable-%1$d"); this.exec = new ThreadPoolExecutor(maxCopyThreads, maxCopyThreads, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), builder.build()); this.exec.allowCoreThreadTimeOut(true); this.copiesPerThread = conf.getInt(REPLICATION_BULKLOAD_COPY_HFILES_PERTHREAD_KEY, REPLICATION_BULKLOAD_COPY_HFILES_PERTHREAD_DEFAULT); sinkFs = FileSystem.get(conf); }
From source file:org.apache.hadoop.hbase.replication.ReplicationTableBase.java
/** * Sets up the thread pool executor used to build the Replication Table in the background * @return the configured executor// w w w.ja va2 s .com */ private Executor setUpExecutor() { ThreadPoolExecutor tempExecutor = new ThreadPoolExecutor(NUM_INITIALIZE_WORKERS, NUM_INITIALIZE_WORKERS, 100, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); ThreadFactoryBuilder tfb = new ThreadFactoryBuilder(); tfb.setNameFormat("ReplicationTableExecutor-%d"); tfb.setDaemon(true); tempExecutor.setThreadFactory(tfb.build()); return tempExecutor; }
From source file:org.diqube.threads.ExecutorManager.java
/** * Create a new cached thread pool, see {@link Executors#newCachedThreadPool()}. * /*from w ww . j av a 2 s. c om*/ * @param nameFormat * a {@link String#format(String, Object...)}-compatible format String, to which a unique integer (0, 1, * etc.) will be supplied as the single parameter. This integer will be unique to the built instance of the * ThreadFactory and will be assigned sequentially. For example, {@code "rpc-pool-%d"} will generate thread * names like {@code "rpc-pool-0"}, {@code "rpc-pool-1"}, {@code "rpc-pool-2"}, etc. * @param uncaughtExceptionHandler * This will be called in case any of the threads of the ExecutorService ends because an exception was * thrown. * * @return The new cached thread pool. */ public ExecutorService newCachedThreadPool(String nameFormat, UncaughtExceptionHandler uncaughtExceptionHandler) { ThreadFactoryBuilder threadFactoryBuilder = new ThreadFactoryBuilder(); threadFactoryBuilder.setNameFormat(nameFormat); threadFactoryBuilder.setUncaughtExceptionHandler(uncaughtExceptionHandler); return Executors.newCachedThreadPool(threadFactoryBuilder.build()); }
From source file:org.diqube.threads.ExecutorManager.java
/** * Create a new {@link ExecutorService} that does create threads as needed, but contains a maxmimum number of threads. * // w ww . j ava 2s . c o m * @param nameFormat * a {@link String#format(String, Object...)}-compatible format String, to which a unique integer (0, 1, * etc.) will be supplied as the single parameter. This integer will be unique to the built instance of the * ThreadFactory and will be assigned sequentially. For example, {@code "rpc-pool-%d"} will generate thread * names like {@code "rpc-pool-0"}, {@code "rpc-pool-1"}, {@code "rpc-pool-2"}, etc. * @param uncaughtExceptionHandler * This will be called in case any of the threads of the ExecutorService ends because an exception was * thrown. * @param maxPoolSize * Maximum number of threads. * @return The new {@link ExecutorService}. */ public ExecutorService newCachedThreadPoolWithMax(String nameFormat, UncaughtExceptionHandler uncaughtExceptionHandler, int maxPoolSize) { ThreadFactoryBuilder threadFactoryBuilder = new ThreadFactoryBuilder(); threadFactoryBuilder.setNameFormat(nameFormat); threadFactoryBuilder.setUncaughtExceptionHandler(uncaughtExceptionHandler); return new ThreadPoolExecutor(0, maxPoolSize, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), threadFactoryBuilder.build()); }
From source file:org.diqube.threads.ExecutorManager.java
/** * Create a new thread pool with a fixed set of threads, see {@link Executors#newFixedThreadPool(int)}. The returned * {@link ExecutorService} should be used for executing a specific diql query, with having the correct * {@link QueryUuidThreadState} set./* ww w . j av a 2s. c om*/ * * <p> * All threads that are used by the returned {@link Executor} will be "bound" to the specific diql query: That means * that in case there is an uncaught exception thrown by one of those threads, the {@link QueryRegistry} will be * informed about this and a potentially installed exception handler for that query will be called. * * <p> * In addition to that, the returned {@link Executor} will also be affected when any of the following methods are * called with the specific query ID: * * <ul> * <li>{@link #findQueryUuidOfExecutorService(ExecutorService)} * <li>{@link #findAllExecutorServicesOfQueryExecution(UUID)} * <li>{@link #shutdownEverythingOfQueryExecution(UUID)} * <li>{@link #shutdownEverythingOfAllQueries()} * </ul> * * <p> * The returned executor will be automatically terminated after {@link ConfigKey#QUERY_EXECUTION_TIMEOUT_SECONDS} * seconds. * * @param numberOfThreads * Number of threads the thread pool should have * @param nameFormat * a {@link String#format(String, Object...)}-compatible format String, to which a unique integer (0, 1, * etc.) will be supplied as the single parameter. This integer will be unique to the built instance of the * ThreadFactory and will be assigned sequentially. For example, {@code "rpc-pool-%d"} will generate thread * names like {@code "rpc-pool-0"}, {@code "rpc-pool-1"}, {@code "rpc-pool-2"}, etc. * @param queryUuid * The UUID to whose execution the returned {@link Executor} belongs to. For a description of query * UUID/executor UUID, see {@link QueryUuid} and ExecutablePlan. * @param executionUuid * The UUID of the execution the returned {@link Executor} belongs to. For a description of query * UUID/executor UUID, see {@link QueryUuid} and ExecutablePlan. * * @return The new thread pool. It is not a {@link ExecutorService}, but only an {@link Executor} returned, because * ONLY the {@link Executor#execute(Runnable)} method must be run, because then the exception forwarding which * is described above will work correctly. This does not work when the method * {@link ExecutorService#submit(java.util.concurrent.Callable)} etc. are called, becuase the ExecutorService * won't forward the exception in that case, but encapsulate it in the corresponding {@link Future}. */ public synchronized Executor newQueryFixedThreadPoolWithTimeout(int numberOfThreads, String nameFormat, UUID queryUuid, UUID executionUuid) { ThreadFactoryBuilder baseThreadFactoryBuilder = new ThreadFactoryBuilder(); baseThreadFactoryBuilder.setNameFormat(nameFormat); // Use our ThreadFactory as facette in order to install our exception handling and enable the publication of the // query & execution UUID in QueryUuid when any thread of the query starts running. ThreadFactory threadFactory = new QueryThreadFactory(baseThreadFactoryBuilder.build(), queryUuid, executionUuid, queryRegistry); DiqubeFixedThreadPoolExecutor res = new DiqubeFixedThreadPoolExecutor(numberOfThreads, threadFactory, queryUuid, executionUuid); res.setThreadNameFormatForToString(nameFormat); synchronized (queryExecutors) { if (!queryExecutors.containsKey(queryUuid)) queryExecutors.put(queryUuid, new HashMap<>()); if (!queryExecutors.get(queryUuid).containsKey(executionUuid)) queryExecutors.get(queryUuid).put(executionUuid, new ArrayList<>()); queryExecutors.get(queryUuid).get(executionUuid).add(res); } timeoutThread.registerTimeout((System.nanoTime() / (long) 1e6) + (queryExecutionTimeoutSeconds * 1000), res); return res; }