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

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

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

ThreadPoolExecutor.prestartAllCoreThreads介绍

[英]Starts all core threads, causing them to idly wait for work. This overrides the default policy of starting core threads only when new tasks are executed.
[中]启动所有核心线程,使它们空闲地等待工作。这将覆盖仅在执行新任务时启动核心线程的默认策略。

代码示例

代码示例来源:origin: oracle/helidon

@Override
public synchronized ThreadPoolExecutor get() {
  if (null == instance) {
    instance = new ThreadPoolExecutor(corePoolSize,
                     maxPoolSize,
                     keepAliveMinutes,
                     TimeUnit.MINUTES,
                     new LinkedBlockingQueue<>(queueCapacity),
                     new ThreadFactory() {
                       private AtomicInteger value = new AtomicInteger();
                       @Override
                       public Thread newThread(Runnable r) {
                         Thread t = new Thread(null,
                                    r,
                                    threadNamePrefix + value.incrementAndGet());
                         t.setDaemon(isDaemon);
                         return t;
                       }
                     });
    if (prestart) {
      instance.prestartAllCoreThreads();
    }
  }
  return instance;
}

代码示例来源:origin: stanfordnlp/CoreNLP

threadPool.prestartAllCoreThreads();

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

/**
 * 初始化线程池
 */
public void init() {
  executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, TimeUnit.MILLISECONDS,
    ThreadPoolUtils.buildQueue(queueSize), new NamedThreadFactory(threadPoolName));
  if (allowCoreThreadTimeOut) {
    executor.allowCoreThreadTimeOut(true);
  }
  if (prestartAllCoreThreads) {
    executor.prestartAllCoreThreads();
  }
}

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

/**
 * 初始化线程池
 */
public void init() {
  executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, TimeUnit.MILLISECONDS,
    ThreadPoolUtils.buildQueue(queueSize), new NamedThreadFactory(threadPoolName));
  if (allowCoreThreadTimeOut) {
    executor.allowCoreThreadTimeOut(true);
  }
  if (prestartAllCoreThreads) {
    executor.prestartAllCoreThreads();
  }
}

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

executor.prestartAllCoreThreads();
executorThreadsStarted = true;

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

/**
 * @param prestart Prestart flag.
 */
public void startThreads(boolean prestart) {
  execSvc = new IgniteThreadPoolExecutor(nodeId.toString(), null, 40, 40, Long.MAX_VALUE,
    new LinkedBlockingQueue<Runnable>());
  // Improve concurrency for testing.
  if (prestart)
    execSvc.prestartAllCoreThreads();
}

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

this.longCompactions.prestartAllCoreThreads();
this.shortCompactions = new ThreadPoolExecutor(smallThreads, smallThreads, 60,
  TimeUnit.SECONDS, stealJobQueue.getStealFromQueue(),

代码示例来源:origin: Netflix/EVCache

@BeforeSuite
public void setProps() {
  BasicConfigurator.configure();
  Logger.getRootLogger().setLevel(Level.INFO);
  Logger.getLogger(SimpleEVCacheTest.class).setLevel(Level.DEBUG);
  Logger.getLogger(Base.class).setLevel(Level.DEBUG);
  Logger.getLogger(EVCacheImpl.class).setLevel(Level.ERROR);
  Logger.getLogger(EVCacheClient.class).setLevel(Level.DEBUG);
  Logger.getLogger(EVCacheClientPool.class).setLevel(Level.DEBUG);
  System.setProperty("EVCACHE.use.simple.node.list.provider", "true");
  System.setProperty("EVCACHE.EVCacheClientPool.readTimeout", "1000");
  System.setProperty("EVCACHE.operation.timeout", "100000");
  System.setProperty("EVCACHE.EVCacheClientPool.bulkReadTimeout", "10000");
  int maxThreads = 2;
  final BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(100000);
  pool = new ThreadPoolExecutor(maxThreads * 4, maxThreads * 4, 30, TimeUnit.SECONDS, queue);
  pool.prestartAllCoreThreads();
}

代码示例来源: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: apache/hbase

stealPool.prestartAllCoreThreads();

代码示例来源:origin: Netflix/EVCache

public EVCacheClientUtil(EVCacheClientPool pool) {
  this._pool = pool;
  this._appName = pool.getAppName();
  this.addDataSizeSummary = EVCacheMetricsFactory.getDistributionSummary(_appName + "-AddData-Size", _appName, null);
  this.addTTLSummary = EVCacheMetricsFactory.getDistributionSummary(_appName + "-AddData-TTL", _appName, null);
  this.fixup = EVCacheConfig.getInstance().getDynamicBooleanProperty(_appName + ".addOperation.fixup", Boolean.FALSE);
  this.fixupPoolSize = EVCacheConfig.getInstance().getDynamicIntProperty(_appName + ".addOperation.fixup.poolsize", 10);
  RejectedExecutionHandler block = new RejectedExecutionHandler() {
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
      EVCacheMetricsFactory.increment(_appName , null, null, _appName + "-AddCall-FixUp-REJECTED");
    }
  };
  
  class SimpleThreadFactory implements ThreadFactory {
    private final AtomicInteger counter = new AtomicInteger(); 
    public Thread newThread(Runnable r) {
     return new Thread(r, "EVCacheClientUtil-AddFixUp-" + counter.getAndIncrement());
    }
   }
  final BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(10000);
  threadPool = new ThreadPoolExecutor(fixupPoolSize.get(), fixupPoolSize.get() * 2, 30, TimeUnit.SECONDS, queue, new SimpleThreadFactory(), block);
  
  CompositeMonitor<?> newThreadPoolMonitor = Monitors.newThreadPoolMonitor("EVCacheClientUtil-AddFixUp", threadPool);
  DefaultMonitorRegistry.getInstance().register(newThreadPoolMonitor);
  threadPool.prestartAllCoreThreads();
  
}

代码示例来源:origin: org.opendaylight.tsdr/tsdr-syslog-collector

private SyslogDatastoreManager(int coreThreadPoolSize, int maxThreadpoolSize, long keepAliveTime, int queueSize) {
  this.db = null;
  this.threadPool = new ThreadPoolExecutor(coreThreadPoolSize, maxThreadpoolSize, keepAliveTime, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(queueSize));
  this.threadPool.prestartAllCoreThreads();
}

代码示例来源:origin: org.apache.mahout/mahout-mrlegacy

public void start() {
 log.info("Starting training threadpool with {} threads", numTrainThreads);
 workQueue = new ArrayBlockingQueue<Runnable>(numTrainThreads * 10);
 threadPool = new ThreadPoolExecutor(numTrainThreads, numTrainThreads, 0, TimeUnit.SECONDS,
   workQueue);
 threadPool.allowCoreThreadTimeOut(false);
 threadPool.prestartAllCoreThreads();
 writeModel.reset();
}

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

public void start() {
 log.info("Starting training threadpool with {} threads", numTrainThreads);
 workQueue = new ArrayBlockingQueue<Runnable>(numTrainThreads * 10);
 threadPool = new ThreadPoolExecutor(numTrainThreads, numTrainThreads, 0, TimeUnit.SECONDS,
   workQueue);
 threadPool.allowCoreThreadTimeOut(false);
 threadPool.prestartAllCoreThreads();
 writeModel.reset();
}

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

private void init() {
  executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime,
    TimeUnit.MILLISECONDS, ThreadPoolUtils.buildQueue(queueSize), new NamedThreadFactory(
      threadPoolName, isDaemon));
  if (allowCoreThreadTimeOut) {
    executor.allowCoreThreadTimeOut(true);
  }
  if (prestartAllCoreThreads) {
    executor.prestartAllCoreThreads();
  }
}

代码示例来源:origin: com.cloudera.llama/llama

@SuppressWarnings("unchecked")
public void start() throws Exception {
 eventsQueue = new DelayQueue<DelayedRunnable>();
 int threads = conf.getClientNotifierThreads();
 //funny downcasting and upcasting because javac gets goofy here
 executor = new ThreadPoolExecutor(threads, threads, 0, TimeUnit.SECONDS,
   (BlockingQueue<Runnable>) (BlockingQueue) eventsQueue,
   new NamedThreadFactory("llama-notifier"));
 executor.prestartAllCoreThreads();
 subject = Security.loginClientSubject(conf);
}

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

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;
}

相关文章

ThreadPoolExecutor类方法