當前位置: 首頁>>代碼示例>>Java>>正文


Java ThreadPoolExecutor.prestartAllCoreThreads方法代碼示例

本文整理匯總了Java中java.util.concurrent.ThreadPoolExecutor.prestartAllCoreThreads方法的典型用法代碼示例。如果您正苦於以下問題:Java ThreadPoolExecutor.prestartAllCoreThreads方法的具體用法?Java ThreadPoolExecutor.prestartAllCoreThreads怎麽用?Java ThreadPoolExecutor.prestartAllCoreThreads使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.concurrent.ThreadPoolExecutor的用法示例。


在下文中一共展示了ThreadPoolExecutor.prestartAllCoreThreads方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setUp

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
@BeforeExperiment void setUp() throws Exception {
  executorService = new ThreadPoolExecutor(NUM_THREADS,
      NUM_THREADS,
      Long.MAX_VALUE,
      TimeUnit.SECONDS,
      new ArrayBlockingQueue<Runnable>(1000));
  executorService.prestartAllCoreThreads();
  final AtomicInteger integer = new AtomicInteger();
  // Execute a bunch of tasks to ensure that our threads are allocated and hot
  for (int i = 0; i < NUM_THREADS * 10; i++) {
    @SuppressWarnings("unused") // go/futurereturn-lsc
    Future<?> possiblyIgnoredError =
        executorService.submit(
            new Runnable() {
              @Override
              public void run() {
                integer.getAndIncrement();
              }
            });
  }
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:22,代碼來源:ExecutionListBenchmark.java

示例2: multiThreadUpload

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
private ThreadPoolExecutor multiThreadUpload(int threadNum, final int threadFileNum) {

    ThreadPoolExecutor pool = (ThreadPoolExecutor) Executors.newFixedThreadPool(threadNum);
    pool.prestartAllCoreThreads();

    for (int i = 0; i < threadNum; ++i) {
      final int threadId = i;
      pool.submit(new Runnable() {
        @Override
        public void run() {
          uploadAndDownloadPerform(threadId, threadFileNum);
        }
      });
    }
    pool.shutdown();
    return pool;
  }
 
開發者ID:XiaoMi,項目名稱:ECFileCache,代碼行數:18,代碼來源:FileCachePerf.java

示例3: testPrestartAllCoreThreads

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
/**
 * prestartAllCoreThreads starts all corePoolSize threads
 */
public void testPrestartAllCoreThreads() {
    final ThreadPoolExecutor p =
        new ThreadPoolExecutor(2, 6,
                               LONG_DELAY_MS, MILLISECONDS,
                               new ArrayBlockingQueue<Runnable>(10));
    try (PoolCleaner cleaner = cleaner(p)) {
        assertEquals(0, p.getPoolSize());
        p.prestartAllCoreThreads();
        assertEquals(2, p.getPoolSize());
        p.prestartAllCoreThreads();
        assertEquals(2, p.getPoolSize());
        p.setCorePoolSize(4);
        p.prestartAllCoreThreads();
        assertEquals(4, p.getPoolSize());
        p.prestartAllCoreThreads();
        assertEquals(4, p.getPoolSize());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:ThreadPoolExecutorTest.java

示例4: testPrestartAllCoreThreads

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
/**
 * prestartAllCoreThreads starts all corePoolSize threads
 */
public void testPrestartAllCoreThreads() {
    final ThreadPoolExecutor p =
        new CustomTPE(2, 6,
                      LONG_DELAY_MS, MILLISECONDS,
                      new ArrayBlockingQueue<Runnable>(10));
    try (PoolCleaner cleaner = cleaner(p)) {
        assertEquals(0, p.getPoolSize());
        p.prestartAllCoreThreads();
        assertEquals(2, p.getPoolSize());
        p.prestartAllCoreThreads();
        assertEquals(2, p.getPoolSize());
        p.setCorePoolSize(4);
        p.prestartAllCoreThreads();
        assertEquals(4, p.getPoolSize());
        p.prestartAllCoreThreads();
        assertEquals(4, p.getPoolSize());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:ThreadPoolExecutorSubclassTest.java

示例5: setUp

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
@BeforeExperiment void setUp() throws Exception {
  executorService = new ThreadPoolExecutor(NUM_THREADS,
      NUM_THREADS,
      Long.MAX_VALUE,
      TimeUnit.SECONDS,
      new ArrayBlockingQueue<Runnable>(1000));
  executorService.prestartAllCoreThreads();
  final AtomicInteger integer = new AtomicInteger();
  // Execute a bunch of tasks to ensure that our threads are allocated and hot
  for (int i = 0; i < NUM_THREADS * 10; i++) {
    executorService.submit(new Runnable() {
      @Override public void run() {
        integer.getAndIncrement();
      }
    });
  }
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:18,代碼來源:ExecutionListBenchmark.java

示例6: test

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
public void test(int nTasks, int nParallel) {
	
	
	for(int i=0; i<nTasks; i++) {
		System.err.println(i);
		ThreadPoolExecutor pool = (ThreadPoolExecutor) Executors.newFixedThreadPool(nParallel);
		pool.prestartAllCoreThreads();
		for(int k=0; k<nParallel; k++) pool.submit(new Task());
		try { waitComplete(); }
		catch(Exception e) { e.printStackTrace(); }
		pool.shutdown();
	}
	
}
 
開發者ID:attipaci,項目名稱:crush,代碼行數:15,代碼來源:UlimitTest.java

示例7: createExecutorService

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
private ExecutorService createExecutorService(int poolSize, int workQueueMaxSize, boolean
        prestartThreadPool) {

    logger.info("create HConnectionThreadPoolExecutor poolSize:{}, workerQueueMaxSize:{}",
            poolSize, workQueueMaxSize);

    ThreadPoolExecutor threadPoolExecutor = ExecutorFactory.newFixedThreadPool(poolSize,
            workQueueMaxSize, "Pinpoint-HConnectionExecutor", true);
    if (prestartThreadPool) {
        logger.info("prestartAllCoreThreads");
        threadPoolExecutor.prestartAllCoreThreads();
    }

    return threadPoolExecutor;
}
 
開發者ID:fchenxi,項目名稱:easyhbase,代碼行數:16,代碼來源:PooledHTableFactory.java

示例8: AsyncCacheLoader

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
public AsyncCacheLoader(Component component) {
    ThreadPoolExecutor pool = new ThreadPoolExecutor(
            1, 1, Long.MAX_VALUE, TimeUnit.MINUTES, new LinkedBlockingQueue<>()
    );
    pool.allowCoreThreadTimeOut(false);
    pool.prestartAllCoreThreads();
    lex = MoreExecutors.listeningDecorator(pool);
    this.component = component;
}
 
開發者ID:CLARIN-PL,項目名稱:WordnetLoom,代碼行數:10,代碼來源:ToolTipList.java

示例9: RedisAccessParallel

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
public RedisAccessParallel(Map<Integer, String> redisMap) {
  super(redisMap);
  this.checkResultTimeoutMs = Config.getInstance().getCheckJedisResultTimeoutMs();

  pool = (ThreadPoolExecutor) Executors.newFixedThreadPool(Config.getInstance().getRedisAccessThreadNum());
  pool.prestartAllCoreThreads();
}
 
開發者ID:XiaoMi,項目名稱:ECFileCache,代碼行數:8,代碼來源:RedisAccessParallel.java

示例10: FlexibleThreadPoolWrapper

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
private FlexibleThreadPoolWrapper(int minThreadCount, int maxThreadCount, long keepAlive, TimeUnit timeUnit,
        ThreadFactory threadFactory, BlockingQueue<Runnable> queue) {

    executor = new ThreadPoolExecutor(minThreadCount, maxThreadCount, keepAlive, timeUnit,
            queue, threadFactory, new FlexibleRejectionHandler());
    executor.prestartAllCoreThreads();
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:8,代碼來源:FlexibleThreadPoolWrapper.java

示例11: createExecutor

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
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");
  ThreadPoolExecutor pool = new ThreadPoolExecutor(workerThreads, workerThreads,
          Long.MAX_VALUE, TimeUnit.SECONDS, callQueue, tfb.build());
  pool.prestartAllCoreThreads();
  return pool;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:13,代碼來源:ThriftServer.java

示例12: init

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
public  void init (){

        RejectedExecutionHandlerImpl rejectionHandler = new RejectedExecutionHandlerImpl();

        ThreadFactory threadFactory = Executors.defaultThreadFactory();

        executorPool = new ThreadPoolExecutor(CORE, MAX, TIMEOUT, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(100),
                threadFactory, rejectionHandler);

        monitor = new MyMonitorThread(executorPool, 15);
        Thread monitorThread = new Thread(monitor);
        monitorThread.start();

        executorPool.prestartAllCoreThreads();

    }
 
開發者ID:HttpRequester,項目名稱:Requester,代碼行數:17,代碼來源:ConnectionThreadPool.java


注:本文中的java.util.concurrent.ThreadPoolExecutor.prestartAllCoreThreads方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。