本文整理汇总了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();
}
});
}
}
示例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;
}
示例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());
}
}
示例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());
}
}
示例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();
}
});
}
}
示例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();
}
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}