Guava ThreadFactoryBuilder - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Guava ThreadFactoryBuilder class.

This code example shows how to use the following methods:
 
    public ScheduledExecutorServiceBuilder(LifecycleEnvironment environment, String nameFormat, boolean useDaemonThreads) {
        this.environment = environment;
        this.nameFormat = nameFormat;
        this.poolSize = 1;
        this.threadFactory = new ThreadFactoryBuilder().setNameFormat(nameFormat).setDaemon(useDaemonThreads).build();
        this.shutdownTime = Duration.seconds(5);
        this.handler = new ThreadPoolExecutor.AbortPolicy();
    } 
 
    public ScheduledExecutorServiceBuilder threads(int threads) {
        this.poolSize = threads;
        return this;
    } 
 
    public ScheduledExecutorServiceBuilder shutdownTime(Duration time) {
        this.shutdownTime = time;
        return this;
    } 
 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:build, setDaemon, setNameFormat
This code example shows how to use the following methods:build, setNameFormat, setPriority
This code example shows how to use the following methods:
        this.corePoolSize = 0;
        this.maximumPoolSize = Integer.MAX_VALUE;
        this.keepAliveTime = Duration.seconds(60);
        this.shutdownTime = Duration.seconds(5);
        this.workQueue = new LinkedBlockingQueue<>();
        this.threadFactory = new ThreadFactoryBuilder().setNameFormat(nameFormat).build();
        this.handler = new ThreadPoolExecutor.AbortPolicy();
    } 
 
    public ExecutorServiceBuilder minThreads(int threads) {
        this.corePoolSize = threads;
        return this;
    } 
 
    public ExecutorServiceBuilder maxThreads(int threads) {
        this.maximumPoolSize = threads;
        return this;
    } 
 
    public ExecutorServiceBuilder keepAliveTime(Duration time) {
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:build, setDaemon, setNameFormat
 
  private static ExecutorService createExecutor(
      int workerThreads, ThriftMetrics metrics) {
    CallQueue callQueue = new CallQueue(
        new LinkedBlockingQueue<Call>(), metrics);
    ThreadFactoryBuilder tfb = new ThreadFactoryBuilder();
    tfb.setDaemon(true);
    tfb.setNameFormat("thrift2-worker-%d");
    return new ThreadPoolExecutor(workerThreads, workerThreads,
            Long.MAX_VALUE, TimeUnit.SECONDS, callQueue, tfb.build());
  } 
 
  private static TServer getTThreadPoolServer(TProtocolFactory protocolFactory, THBaseService.Processor processor,
      TTransportFactory transportFactory, InetSocketAddress inetSocketAddress) throws TTransportException {
    TServerTransport serverTransport = new TServerSocket(inetSocketAddress);
    log.info("starting HBase ThreadPool Thrift server on " + inetSocketAddress.toString());
    TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport);
    serverArgs.processor(processor);
    serverArgs.transportFactory(transportFactory);
    serverArgs.protocolFactory(protocolFactory);
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 
		// 任何异常不会中断schedule执行, 由Spring TaskUtils的LOG_AND_SUPPRESS_ERROR_HANDLER進行处理 
		Runnable task = TaskUtils.decorateTaskWithErrorHandler(this, null, true);
 
		// 创建单线程的SechdulerExecutor,并用guava的ThreadFactoryBuilder设定生成线程的名称 
		scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setNameFormat(
				"JdkTimerJob-%1$d").build());
 
		// scheduleAtFixedRatefixRate() 固定任务两次启动之间的时间间隔. 
		// scheduleAtFixedDelay() 固定任务结束后到下一次启动间的时间间隔. 
		scheduledExecutorService.scheduleAtFixedRate(task, initialDelay, period, TimeUnit.SECONDS);
	} 
 
	@PreDestroy 
	public void stop() { 
		Threads.normalShutdown(scheduledExecutorService, shutdownTimeout, TimeUnit.SECONDS);
	} 
 
	/** 
	 * 定时打印当前用户数到日志. 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
	/** 
	 * 创建ThreadFactory,使得创建的线程有自己的名字而不是默认的"pool-x-thread-y", 
	 * 在用threaddump查看线程时特别有用。 格式如"mythread-%d",使用了Guava的工具类 
	 */ 
	public static ThreadFactory buildJobFactory(String nameFormat) {
		return new ThreadFactoryBuilder().setNameFormat(nameFormat).build();
	} 
 
	/** 
	 * 按照ExecutorService JavaDoc示例代码编写的Graceful Shutdown方法. 
	 * 先使用shutdown, 停止接收新任务并尝试完成所有已存在任务. 
	 * 如果超时, 则调用shutdownNow, 取消在workQueue中Pending的任务,并中断所有阻塞函数. 
	 * 如果仍然超時,則強制退出. 
	 * 另对在shutdown时线程本身被调用中断做了处理. 
	 */ 
	public static void gracefulShutdown(ExecutorService pool, int shutdownTimeout, int shutdownNowTimeout,
			TimeUnit timeUnit) {
		pool.shutdown(); // Disable new tasks from being submitted
		try { 
			// Wait a while for existing tasks to terminate 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
         @Named(PROPERTY_SCHEDULER_THREADS) ListeningScheduledExecutorService in) {
      return in;
   } 
 
   private static ListeningScheduledExecutorService newScheduledThreadPoolNamed(String name, int maxCount) {
      ThreadFactory factory = new ThreadFactoryBuilder().setNameFormat(name).setThreadFactory(defaultThreadFactory())
            .build();
      return listeningDecorator(maxCount == 0 ? newSingleThreadScheduledExecutor(factory) : newScheduledThreadPool(
            maxCount, factory));
   } 
 
   @Override 
   protected void configure() { // NO_UCD 
   } 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:build, setNameFormat
        this.threadFactory = factory;
        this.handler = new ThreadPoolExecutor.AbortPolicy();
    } 
 
    public ExecutorServiceBuilder(LifecycleEnvironment environment, String nameFormat) {
        this(environment, nameFormat, new ThreadFactoryBuilder().setNameFormat(nameFormat).build());
    } 
 
    public ExecutorServiceBuilder minThreads(int threads) {
        this.corePoolSize = threads;
        return this;
    } 
 
    public ExecutorServiceBuilder maxThreads(int threads) {
        this.maximumPoolSize = threads;
        return this;
    } 
 
    public ExecutorServiceBuilder keepAliveTime(Duration time) {
        this.keepAliveTime = time;
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
See Code Examples for Guava ThreadFactoryBuilder Methods: