java.util.concurrent.ThreadPoolExecutor.setThreadFactory()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(180)

本文整理了Java中java.util.concurrent.ThreadPoolExecutor.setThreadFactory()方法的一些代码示例,展示了ThreadPoolExecutor.setThreadFactory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThreadPoolExecutor.setThreadFactory()方法的具体详情如下:
包路径:java.util.concurrent.ThreadPoolExecutor
类名称:ThreadPoolExecutor
方法名:setThreadFactory

ThreadPoolExecutor.setThreadFactory介绍

[英]Sets the thread factory used to create new threads.
[中]设置用于创建新线程的线程工厂。

代码示例

代码示例来源:origin: wildfly/wildfly

public TP setThreadPoolThreadFactory(ThreadFactory factory) {
  thread_factory=factory;
  if(thread_pool instanceof ThreadPoolExecutor)
    ((ThreadPoolExecutor)thread_pool).setThreadFactory(factory);
  return this;
}

代码示例来源:origin: wildfly/wildfly

public TP setInternalThreadPoolThreadFactory(ThreadFactory factory) {
  internal_thread_factory=factory;
  if(internal_pool instanceof ThreadPoolExecutor)
    ((ThreadPoolExecutor)internal_pool).setThreadFactory(factory);
  return this;
}

代码示例来源:origin: google/guava

@GwtIncompatible // TODO
private static void useDaemonThreadFactory(ThreadPoolExecutor executor) {
 executor.setThreadFactory(
   new ThreadFactoryBuilder()
     .setDaemon(true)
     .setThreadFactory(executor.getThreadFactory())
     .build());
}

代码示例来源:origin: wildfly/wildfly

public void    setThreadFactory(ThreadFactory f)     {condSet((p) -> p.setThreadFactory(f));}
public void    setThreadPool(Executor new_pool)      {pool=new_pool;}

代码示例来源:origin: org.apache.hadoop/hadoop-common

private ReadaheadPool() {
 pool = new ThreadPoolExecutor(POOL_SIZE, MAX_POOL_SIZE, 3L, TimeUnit.SECONDS,
   new ArrayBlockingQueue<Runnable>(CAPACITY));
 pool.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardOldestPolicy());
 pool.setThreadFactory(new ThreadFactoryBuilder()
  .setDaemon(true)
  .setNameFormat("Readahead Thread #%d")
  .build());
}

代码示例来源:origin: google/j2objc

@GwtIncompatible // TODO
private static void useDaemonThreadFactory(ThreadPoolExecutor executor) {
 executor.setThreadFactory(
   new ThreadFactoryBuilder()
     .setDaemon(true)
     .setThreadFactory(executor.getThreadFactory())
     .build());
}

代码示例来源:origin: wildfly/wildfly

protected ThreadPoolExecutor createThreadPool() {
  ThreadPoolExecutor threadPool=new ThreadPoolExecutor(0, max_pool, pool_thread_keep_alive,
                             TimeUnit.MILLISECONDS, new SynchronousQueue<>());
  ThreadFactory factory=new ThreadFactory() {
    private final AtomicInteger thread_id=new AtomicInteger(1);
    public Thread newThread(final Runnable command) {
      return getThreadFactory().newThread(command, "StreamingStateTransfer-sender-" + thread_id.getAndIncrement());
    }
  };
  threadPool.setRejectedExecutionHandler(new ShutdownRejectedExecutionHandler(threadPool.getRejectedExecutionHandler()));
  threadPool.setThreadFactory(factory);
  return threadPool;
}

代码示例来源:origin: wildfly/wildfly

@GwtIncompatible // TODO
private static void useDaemonThreadFactory(ThreadPoolExecutor executor) {
 executor.setThreadFactory(
   new ThreadFactoryBuilder()
     .setDaemon(true)
     .setThreadFactory(executor.getThreadFactory())
     .build());
}

代码示例来源:origin: spring-projects/spring-framework

@Override
protected AsyncListenableTaskExecutor buildExecutor() {
  concurrentExecutor.setThreadFactory(new CustomizableThreadFactory(THREAD_NAME_PREFIX));
  return new ConcurrentTaskExecutor(concurrentExecutor);
}

代码示例来源:origin: apache/hbase

tfb.setNameFormat("ReplicationExecutor-%d");
tfb.setDaemon(true);
this.executor.setThreadFactory(tfb.build());
this.latestPaths = new HashMap<>();
this.replicationForBulkLoadDataEnabled = conf.getBoolean(

代码示例来源:origin: prestodb/presto

@GwtIncompatible // TODO
private static void useDaemonThreadFactory(ThreadPoolExecutor executor) {
 executor.setThreadFactory(
   new ThreadFactoryBuilder()
     .setDaemon(true)
     .setThreadFactory(executor.getThreadFactory())
     .build());
}

代码示例来源:origin: alipay/sofa-rpc

protected ThreadPoolExecutor initThreadPool(ServerConfig serverConfig) {
  ThreadPoolExecutor threadPool = BusinessPool.initPool(serverConfig);
  threadPool.setThreadFactory(new NamedThreadFactory("SEV-" + serverConfig.getProtocol().toUpperCase()
    + "-BIZ-" + serverConfig.getPort(), serverConfig.isDaemon()));
  threadPool.setRejectedExecutionHandler(new SofaRejectedExecutionHandler());
  if (serverConfig.isPreStartCore()) { // 初始化核心线程池
    threadPool.prestartAllCoreThreads();
  }
  return threadPool;
}

代码示例来源:origin: alipay/sofa-rpc

protected ThreadPoolExecutor initThreadPool(ServerConfig serverConfig) {
  ThreadPoolExecutor threadPool = BusinessPool.initPool(serverConfig);
  threadPool.setThreadFactory(new NamedThreadFactory("SEV-" + serverConfig.getProtocol().toUpperCase()
    + "-BIZ-" + serverConfig.getPort(), serverConfig.isDaemon()));
  threadPool.setRejectedExecutionHandler(new SofaRejectedExecutionHandler());
  if (serverConfig.isPreStartCore()) { // 初始化核心线程池
    threadPool.prestartAllCoreThreads();
  }
  return threadPool;
}

代码示例来源:origin: alipay/sofa-rpc

protected ThreadPoolExecutor initThreadPool(ServerConfig serverConfig) {
  ThreadPoolExecutor threadPool = BusinessPool.initPool(serverConfig);
  threadPool.setThreadFactory(new NamedThreadFactory(
    "SEV-BOLT-BIZ-" + serverConfig.getPort(), serverConfig.isDaemon()));
  threadPool.setRejectedExecutionHandler(new SofaRejectedExecutionHandler());
  if (serverConfig.isPreStartCore()) { // 初始化核心线程池
    threadPool.prestartAllCoreThreads();
  }
  return threadPool;
}

代码示例来源:origin: alipay/sofa-rpc

protected ThreadPoolExecutor initThreadPool(ServerConfig serverConfig) {
  ThreadPoolExecutor threadPool = BusinessPool.initPool(serverConfig);
  threadPool.setThreadFactory(new NamedThreadFactory(
    "SEV-BOLT-BIZ-" + serverConfig.getPort(), serverConfig.isDaemon()));
  threadPool.setRejectedExecutionHandler(new SofaRejectedExecutionHandler());
  if (serverConfig.isPreStartCore()) { // 初始化核心线程池
    threadPool.prestartAllCoreThreads();
  }
  return threadPool;
}

代码示例来源:origin: igniterealtime/Openfire

final ThreadPoolExecutor eventExecutor = (ThreadPoolExecutor) executorFilter.getExecutor();
final ThreadFactory threadFactory = new NamedThreadFactory( name + "-thread-", eventExecutor.getThreadFactory(), true, null );
eventExecutor.setThreadFactory( threadFactory );

代码示例来源:origin: org.eclipse.jetty/jetty-util

private ExecutorThreadPool(ThreadPoolExecutor executor, int minThreads, int reservedThreads, ThreadGroup group)
{
  int maxThreads = executor.getMaximumPoolSize();
  if (maxThreads < minThreads)
  {
    executor.shutdownNow();
    throw new IllegalArgumentException("max threads (" + maxThreads + ") cannot be less than min threads (" + minThreads + ")");
  }
  _executor = executor;
  _executor.setThreadFactory(this::newThread);
  _group = group;
  _minThreads = minThreads;
  _reservedThreads = reservedThreads;
  _budget = new ThreadPoolBudget(this);
}

代码示例来源:origin: apache/activemq-artemis

public void setDefaultThreadPoolThreadFactory(ThreadFactory factory) {
  default_thread_factory=factory;
  if(thread_pool instanceof ThreadPoolExecutor)
    ((ThreadPoolExecutor)thread_pool).setThreadFactory(factory);
}

代码示例来源:origin: apache/activemq-artemis

protected static ExecutorService createThreadPool(int min_threads, int max_threads, long keep_alive_time,
                         final org.apache.activemq.artemis.shaded.org.jgroups.util.ThreadFactory factory) {
  ThreadPoolExecutor pool=new ThreadPoolExecutor(min_threads, max_threads, keep_alive_time,
                          TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>());
  pool.setThreadFactory(factory);
  pool.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
  return pool;
}

代码示例来源:origin: org.apache.storm/storm-core

public FlusherPool() {
  _exec = new ThreadPoolExecutor(1, getNumFlusherPoolThreads(), 10, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1024), new ThreadPoolExecutor.DiscardPolicy());
  ThreadFactory threadFactory = new ThreadFactoryBuilder()
      .setDaemon(true)
      .setNameFormat(THREAD_PREFIX + "-task-pool")
      .build();
  _exec.setThreadFactory(threadFactory);
}

相关文章

ThreadPoolExecutor类方法