本文整理汇总了Java中java.util.concurrent.ThreadPoolExecutor.setMaximumPoolSize方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadPoolExecutor.setMaximumPoolSize方法的具体用法?Java ThreadPoolExecutor.setMaximumPoolSize怎么用?Java ThreadPoolExecutor.setMaximumPoolSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.ThreadPoolExecutor
的用法示例。
在下文中一共展示了ThreadPoolExecutor.setMaximumPoolSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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() ;
}
示例2: 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);
}
}
示例3: 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);
}
示例4: 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);
}
示例5: 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);
}
}
}
示例6: 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);
}
}
}
示例7: 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);
}
}
}
示例8: 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);
}
}
}
示例9: 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);
}
}
示例10: 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);
}
}
}
示例11: testGetMaximumPoolSize
import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
* getMaximumPoolSize returns value given in constructor if not
* otherwise set
*/
public void testGetMaximumPoolSize() {
final ThreadPoolExecutor p =
new ThreadPoolExecutor(2, 3,
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(p)) {
assertEquals(3, p.getMaximumPoolSize());
p.setMaximumPoolSize(5);
assertEquals(5, p.getMaximumPoolSize());
p.setMaximumPoolSize(4);
assertEquals(4, p.getMaximumPoolSize());
}
}
示例12: testMaximumPoolSizeIllegalArgumentException
import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
* setMaximumPoolSize(int) throws IllegalArgumentException if
* given a value less the core pool size
*/
public void testMaximumPoolSizeIllegalArgumentException() {
final ThreadPoolExecutor p =
new ThreadPoolExecutor(2, 3,
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(p)) {
try {
p.setMaximumPoolSize(1);
shouldThrow();
} catch (IllegalArgumentException success) {}
}
}
示例13: testMaximumPoolSizeIllegalArgumentException2
import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
* setMaximumPoolSize throws IllegalArgumentException
* if given a negative value
*/
public void testMaximumPoolSizeIllegalArgumentException2() {
final ThreadPoolExecutor p =
new ThreadPoolExecutor(2, 3,
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(p)) {
try {
p.setMaximumPoolSize(-1);
shouldThrow();
} catch (IllegalArgumentException success) {}
}
}
示例14: testGetMaximumPoolSize
import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
* getMaximumPoolSize returns value given in constructor if not
* otherwise set
*/
public void testGetMaximumPoolSize() {
final ThreadPoolExecutor p =
new CustomTPE(2, 3,
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(p)) {
assertEquals(3, p.getMaximumPoolSize());
p.setMaximumPoolSize(5);
assertEquals(5, p.getMaximumPoolSize());
p.setMaximumPoolSize(4);
assertEquals(4, p.getMaximumPoolSize());
}
}
示例15: testMaximumPoolSizeIllegalArgumentException
import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
* setMaximumPoolSize(int) throws IllegalArgumentException
* if given a value less the core pool size
*/
public void testMaximumPoolSizeIllegalArgumentException() {
final ThreadPoolExecutor p =
new CustomTPE(2, 3,
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(p)) {
try {
p.setMaximumPoolSize(1);
shouldThrow();
} catch (IllegalArgumentException success) {}
}
}