本文整理汇总了Java中java.util.concurrent.ThreadPoolExecutor.setCorePoolSize方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadPoolExecutor.setCorePoolSize方法的具体用法?Java ThreadPoolExecutor.setCorePoolSize怎么用?Java ThreadPoolExecutor.setCorePoolSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.ThreadPoolExecutor
的用法示例。
在下文中一共展示了ThreadPoolExecutor.setCorePoolSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPrestartCoreThread
import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
* prestartCoreThread starts a thread if under corePoolSize, else doesn't
*/
public void testPrestartCoreThread() {
final ThreadPoolExecutor p =
new ThreadPoolExecutor(2, 6,
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(p)) {
assertEquals(0, p.getPoolSize());
assertTrue(p.prestartCoreThread());
assertEquals(1, p.getPoolSize());
assertTrue(p.prestartCoreThread());
assertEquals(2, p.getPoolSize());
assertFalse(p.prestartCoreThread());
assertEquals(2, p.getPoolSize());
p.setCorePoolSize(4);
assertTrue(p.prestartCoreThread());
assertEquals(3, p.getPoolSize());
assertTrue(p.prestartCoreThread());
assertEquals(4, p.getPoolSize());
assertFalse(p.prestartCoreThread());
assertEquals(4, p.getPoolSize());
}
}
示例2: 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());
}
}
示例3: testPrestartCoreThread
import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
* prestartCoreThread starts a thread if under corePoolSize, else doesn't
*/
public void testPrestartCoreThread() {
final ThreadPoolExecutor p =
new CustomTPE(2, 6,
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(p)) {
assertEquals(0, p.getPoolSize());
assertTrue(p.prestartCoreThread());
assertEquals(1, p.getPoolSize());
assertTrue(p.prestartCoreThread());
assertEquals(2, p.getPoolSize());
assertFalse(p.prestartCoreThread());
assertEquals(2, p.getPoolSize());
p.setCorePoolSize(4);
assertTrue(p.prestartCoreThread());
assertEquals(3, p.getPoolSize());
assertTrue(p.prestartCoreThread());
assertEquals(4, p.getPoolSize());
assertFalse(p.prestartCoreThread());
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: testingOnlyPostEvent
import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
public void testingOnlyPostEvent ( MultiValueMap<String, String> formParams )
throws Exception {
// Support for LT. do not blow through queue
if ( numSent++ % 1000 == 0 ) {
logger.info( "Messages sent: " + numSent + " backlog: " + eventPostQueue.size() );
}
ThreadPoolExecutor pool = (ThreadPoolExecutor) eventPostPool;
if ( eventPostQueue.size() > 100 && pool.getCorePoolSize() == 1 ) {
pool.setCorePoolSize( 6 );
pool.setMaximumPoolSize( 6 );
}
// blocking for testing
logger.info( "eventPostPool terminated: {}", eventPostPool.isTerminated() );
Future<String> futureResult = eventPostPool.submit( new EventPostRunnable( lifecycleSettings.getEventUrl(),
formParams, "test", "test" ) );
// Non Blocking to test event caching/pooling
// futureResult.get() ;
}
示例6: setStartStopThreads
import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
@Override
public void setStartStopThreads(int startStopThreads) {
this.startStopThreads = startStopThreads;
// Use local copies to ensure thread safety
ThreadPoolExecutor executor = startStopExecutor;
if (executor != null) {
int newThreads = getStartStopThreadsInternal();
executor.setMaximumPoolSize(newThreads);
executor.setCorePoolSize(newThreads);
}
}
示例7: KanboardAPI
import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
public KanboardAPI(String serverURL, final String username, final String password) throws IOException {
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password.toCharArray());
}
});
kanboardURL = KanboardAPI.sanitizeURL(serverURL.trim());
Log.i(Constants.TAG, String.format("Host uses %s", kanboardURL.getProtocol()));
// threadPoolExecutor = new ThreadPoolExecutor(12, 12, 20, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(256));
threadPoolExecutor = (ThreadPoolExecutor) AsyncTask.THREAD_POOL_EXECUTOR;
threadPoolExecutor.setCorePoolSize(12);
threadPoolExecutor.setMaximumPoolSize(12);
}
示例8: initExecutionPool
import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
private void initExecutionPool(int corePoolSize, int maxPoolSize, long keepAliveTime) {
executorPool = (ThreadPoolExecutor) Executors.newCachedThreadPool();
executorPool.setCorePoolSize(corePoolSize);
executorPool.setMaximumPoolSize(maxPoolSize);
executorPool.setKeepAliveTime(keepAliveTime, TimeUnit.MILLISECONDS);
}
示例9: adjustPoolSize
import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
public void adjustPoolSize(int newPoolSize) {
if (newPoolSize != poolSize) {
poolSize = newPoolSize;
if (executor instanceof ThreadPoolExecutor) {
ThreadPoolExecutor pool = (ThreadPoolExecutor) executor;
pool.setCorePoolSize(newPoolSize);
pool.setMaximumPoolSize(newPoolSize);
}
}
}
示例10: adjustPoolSize
import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
private void adjustPoolSize(DbLoadContext context) {
Pipeline pipeline = context.getPipeline();
int newPoolSize = pipeline.getParameters().getLoadPoolSize();
if (newPoolSize != poolSize) {
poolSize = newPoolSize;
if (executor instanceof ThreadPoolExecutor) {
ThreadPoolExecutor pool = (ThreadPoolExecutor) executor;
pool.setCorePoolSize(newPoolSize);
pool.setMaximumPoolSize(newPoolSize);
}
}
}
示例11: adjustPoolSize
import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
private void adjustPoolSize(FileLoadContext context) {
Pipeline pipeline = context.getPipeline();
int newPoolSize = pipeline.getParameters().getFileLoadPoolSize();
if (newPoolSize != poolSize) {
poolSize = newPoolSize;
if (executor instanceof ThreadPoolExecutor) {
ThreadPoolExecutor pool = (ThreadPoolExecutor) executor;
pool.setCorePoolSize(newPoolSize);
pool.setMaximumPoolSize(newPoolSize);
}
}
}
示例12: adjustPoolSize
import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
private void adjustPoolSize(int newPoolSize) {
if (newPoolSize != poolSize) {
poolSize = newPoolSize;
if (executor instanceof ThreadPoolExecutor) {
ThreadPoolExecutor pool = (ThreadPoolExecutor) executor;
pool.setCorePoolSize(newPoolSize);
pool.setMaximumPoolSize(newPoolSize);
}
}
}
示例13: setStartStopThreads
import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
@Override
public void setStartStopThreads(int startStopThreads) {
this.startStopThreads = startStopThreads;
// Use local copies to ensure thread safety
ThreadPoolExecutor executor = startStopExecutor;
if (executor != null) {
int newThreads = getStartStopThreadsInternal();
executor.setMaximumPoolSize(newThreads);
executor.setCorePoolSize(newThreads);
}
}
示例14: setThreadPoolSize
import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
public void setThreadPoolSize(int size) {
if (executorService instanceof ThreadPoolExecutor) {
ThreadPoolExecutor pool = (ThreadPoolExecutor) executorService;
pool.setCorePoolSize(size);
pool.setMaximumPoolSize(size);
}
}
示例15: fireServerAttributeUpdateEvent
import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
* Fire server attribute update event.
*
* @param source
* the source
* @param attrs
* the config
*/
protected void fireServerAttributeUpdateEvent(JsfUrl source, Map<String, String> attrs) {
LOGGER.info("Get server attribute update callback event, source: {}, data: {}", source, attrs);
if (CommonUtils.isNotEmpty(attrs)) { // 需要区分alias
try {
int port = Integer.parseInt(attrs.get("port"));
ThreadPoolExecutor executor = BusinessPool.getBusinessPool(port);
if (executor != null) {
if (attrs.containsKey("core")) {
int coreNew = Integer.parseInt(attrs.get("core"));
if (coreNew != executor.getCorePoolSize()) {
LOGGER.info("Core pool size of business pool at port {} change from {} to {}",
new Object[]{port, executor.getCorePoolSize(), coreNew});
executor.setCorePoolSize(coreNew);
}
}
if (attrs.containsKey("max")) {
int maxNew = Integer.parseInt(attrs.get("max"));
if (maxNew != executor.getMaximumPoolSize()) {
LOGGER.info("Maximum pool size of business pool at port {} change from {} to {}",
new Object[]{port, executor.getMaximumPoolSize(), maxNew});
executor.setMaximumPoolSize(maxNew);
}
}
}
} catch (Exception e) {
LOGGER.warn("Fire server attribute update event error!", e);
}
}
}