本文整理了Java中java.util.concurrent.ThreadPoolExecutor.setCorePoolSize()
方法的一些代码示例,展示了ThreadPoolExecutor.setCorePoolSize()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThreadPoolExecutor.setCorePoolSize()
方法的具体详情如下:
包路径:java.util.concurrent.ThreadPoolExecutor
类名称:ThreadPoolExecutor
方法名:setCorePoolSize
[英]Sets the core number of threads. This overrides any value set in the constructor. If the new value is smaller than the current value, excess existing threads will be terminated when they next become idle. If larger, new threads will, if needed, be started to execute any queued tasks.
[中]
代码示例来源:origin: spring-projects/spring-framework
/**
* Set the ThreadPoolExecutor's core pool size.
* Default is 1.
* <p><b>This setting can be modified at runtime, for example through JMX.</b>
*/
public void setCorePoolSize(int corePoolSize) {
synchronized (this.poolSizeMonitor) {
this.corePoolSize = corePoolSize;
if (this.threadPoolExecutor != null) {
this.threadPoolExecutor.setCorePoolSize(corePoolSize);
}
}
}
代码示例来源:origin: org.springframework/spring-context
/**
* Set the ThreadPoolExecutor's core pool size.
* Default is 1.
* <p><b>This setting can be modified at runtime, for example through JMX.</b>
*/
public void setCorePoolSize(int corePoolSize) {
synchronized (this.poolSizeMonitor) {
this.corePoolSize = corePoolSize;
if (this.threadPoolExecutor != null) {
this.threadPoolExecutor.setCorePoolSize(corePoolSize);
}
}
}
代码示例来源:origin: wildfly/wildfly
public TP setThreadPoolMinThreads(int size) {
thread_pool_min_threads=size;
if(thread_pool instanceof ThreadPoolExecutor)
((ThreadPoolExecutor)thread_pool).setCorePoolSize(size);
return this;
}
代码示例来源:origin: apache/hbase
@Override
public void setCorePoolSize(int newCoreSize) {
pool.setCorePoolSize(newCoreSize);
}
代码示例来源:origin: igniterealtime/Openfire
/**
* Sets the min number of threads the channel will use for processing messages.
* The channel will automatically de-allocate worker threads as the queue load shrinks,
* down to the defined minimum. This lets the channel consume fewer resources when load
* is low.
*
* @param minThreadCount the min number of threads that can be used by the channel.
*/
public void setMinThreadCount(int minThreadCount) {
executor.setCorePoolSize(minThreadCount);
}
代码示例来源:origin: apache/rocketmq
@Override
public void updateCorePoolSize(int corePoolSize) {
if (corePoolSize > 0
&& corePoolSize <= Short.MAX_VALUE
&& corePoolSize < this.defaultMQPushConsumer.getConsumeThreadMax()) {
this.consumeExecutor.setCorePoolSize(corePoolSize);
}
}
代码示例来源:origin: apache/rocketmq
@Override
public void updateCorePoolSize(int corePoolSize) {
if (corePoolSize > 0
&& corePoolSize <= Short.MAX_VALUE
&& corePoolSize < this.defaultMQPushConsumer.getConsumeThreadMax()) {
this.consumeExecutor.setCorePoolSize(corePoolSize);
}
}
代码示例来源:origin: apache/hbase
/**
* This method samples the incoming requests and, if selected, will check if
* the corePoolSize should be changed.
* @param countersMapSize the size of the counters map
*/
private void dynamicallySetCoreSize(int countersMapSize) {
// Here we are using countersMapSize as a random number, meaning this
// could be a Random object
if (countersMapSize % 10 != 0) {
return;
}
double currentRatio = (double) countersMapSize / (double) maxQueueSize;
int newValue;
if (currentRatio < 0.1) {
newValue = 1;
} else if (currentRatio < 0.3) {
newValue = 2;
} else if (currentRatio < 0.5) {
newValue = 4;
} else if (currentRatio < 0.7) {
newValue = 8;
} else if (currentRatio < 0.9) {
newValue = 14;
} else {
newValue = 22;
}
if (pool.getCorePoolSize() != newValue) {
pool.setCorePoolSize(newValue);
}
}
代码示例来源:origin: wildfly/wildfly
public void setMinThreads(int size) {condSet(p -> p.setCorePoolSize(size));}
public int getMaxThreads() {return condGet(ThreadPoolExecutor::getMaximumPoolSize, 0);}
代码示例来源:origin: wildfly/wildfly
public void setMaximumPoolSize(final int size) {
if (size > getCorePoolSize()) {
super.setMaximumPoolSize(size);
super.setCorePoolSize(size);
} else {
super.setCorePoolSize(size);
super.setMaximumPoolSize(size);
}
}
代码示例来源:origin: ltsopensource/light-task-scheduler
public void setWorkThread(int workThread) {
if (workThread == 0) {
throw new IllegalArgumentException("workThread can not be zero!");
}
threadPoolExecutor.setMaximumPoolSize(workThread);
threadPoolExecutor.setCorePoolSize(workThread);
LOGGER.info("workThread update to {}", workThread);
}
代码示例来源:origin: ltsopensource/light-task-scheduler
public void setWorkThread(int workThread) {
if (workThread == 0) {
throw new IllegalArgumentException("workThread can not be zero!");
}
threadPoolExecutor.setMaximumPoolSize(workThread);
threadPoolExecutor.setCorePoolSize(workThread);
LOGGER.info("workThread update to {}", workThread);
}
代码示例来源:origin: apache/activemq
/**
* Set the number of threads to be used for processing connections. Defaults
* to Integer.MAX_SIZE. Set this value to be lower to reduce the
* number of simultaneous connection attempts. If not set then the maximum number of
* threads will generally be controlled by the transport maxConnections setting:
* {@link TcpTransportServer#setMaximumConnections(int)}.
*<p>
* Note that this setter controls two thread pools because connection attempts
* require 1 thread to start processing the connection and another thread to read from the
* socket and to detect the protocol. Two threads are needed because some transports
* block on socket read so the first thread needs to be able to abort the second thread on timeout.
* Therefore this setting will set each thread pool to the size passed in essentially giving
* 2 times as many potential threads as the value set.
*<p>
* Both thread pools will close idle threads after a period of time
* essentially allowing the thread pools to grow and shrink dynamically based on load.
*
* @see {@link TcpTransportServer#setMaximumConnections(int)}.
* @param maxConnectionThreadPoolSize
*/
public void setMaxConnectionThreadPoolSize(int maxConnectionThreadPoolSize) {
this.maxConnectionThreadPoolSize = maxConnectionThreadPoolSize;
newConnectionExecutor.setCorePoolSize(maxConnectionThreadPoolSize);
newConnectionExecutor.setMaximumPoolSize(maxConnectionThreadPoolSize);
protocolDetectionExecutor.setCorePoolSize(maxConnectionThreadPoolSize);
protocolDetectionExecutor.setMaximumPoolSize(maxConnectionThreadPoolSize);
}
代码示例来源:origin: apache/hbase
if(this.longCompactions.getCorePoolSize() < largeThreads) {
this.longCompactions.setMaximumPoolSize(largeThreads);
this.longCompactions.setCorePoolSize(largeThreads);
} else {
this.longCompactions.setCorePoolSize(largeThreads);
this.longCompactions.setMaximumPoolSize(largeThreads);
if(this.shortCompactions.getCorePoolSize() < smallThreads) {
this.shortCompactions.setMaximumPoolSize(smallThreads);
this.shortCompactions.setCorePoolSize(smallThreads);
} else {
this.shortCompactions.setCorePoolSize(smallThreads);
this.shortCompactions.setMaximumPoolSize(smallThreads);
if(this.splits.getCorePoolSize() < splitThreads) {
this.splits.setMaximumPoolSize(splitThreads);
this.splits.setCorePoolSize(splitThreads);
} else {
this.splits.setCorePoolSize(splitThreads);
this.splits.setMaximumPoolSize(splitThreads);
代码示例来源:origin: apache/incubator-dubbo
if (threads > 0 && (threads != max || threads != core)) {
if (threads < core) {
threadPoolExecutor.setCorePoolSize(threads);
if (core == max) {
threadPoolExecutor.setMaximumPoolSize(threads);
threadPoolExecutor.setMaximumPoolSize(threads);
if (core == max) {
threadPoolExecutor.setCorePoolSize(threads);
代码示例来源:origin: apache/incubator-dubbo
if (threads > 0 && (threads != max || threads != core)) {
if (threads < core) {
threadPoolExecutor.setCorePoolSize(threads);
if (core == max) {
threadPoolExecutor.setMaximumPoolSize(threads);
threadPoolExecutor.setMaximumPoolSize(threads);
if (core == max) {
threadPoolExecutor.setCorePoolSize(threads);
代码示例来源:origin: apache/hbase
private ThreadPoolExecutor disableHandlers(RpcScheduler scheduler) {
ThreadPoolExecutor rpcExecutor=null;
try {
Field ExecutorField = scheduler.getClass().getDeclaredField("executor");
ExecutorField.setAccessible(true);
scheduler.start();
rpcExecutor = (ThreadPoolExecutor) ExecutorField.get(scheduler);
rpcExecutor.setMaximumPoolSize(1);
rpcExecutor.allowCoreThreadTimeOut(true);
rpcExecutor.setCorePoolSize(0);
rpcExecutor.setKeepAliveTime(1, TimeUnit.MICROSECONDS);
// Wait for 2 seconds, so that idle threads will die
Thread.sleep(2000);
} catch (NoSuchFieldException e) {
LOG.error("No such field exception:"+e);
} catch (IllegalAccessException e) {
LOG.error("Illegal access exception:"+e);
} catch (InterruptedException e) {
LOG.error("Interrupted exception:"+e);
}
return rpcExecutor;
}
代码示例来源:origin: PipelineAI/pipeline
private void touchConfig() {
final int dynamicCoreSize = properties.coreSize().get();
final int configuredMaximumSize = properties.maximumSize().get();
int dynamicMaximumSize = properties.actualMaximumSize();
final boolean allowSizesToDiverge = properties.getAllowMaximumSizeToDivergeFromCoreSize().get();
boolean maxTooLow = false;
if (allowSizesToDiverge && configuredMaximumSize < dynamicCoreSize) {
//if user sets maximum < core (or defaults get us there), we need to maintain invariant of core <= maximum
dynamicMaximumSize = dynamicCoreSize;
maxTooLow = true;
}
// In JDK 6, setCorePoolSize and setMaximumPoolSize will execute a lock operation. Avoid them if the pool size is not changed.
if (threadPool.getCorePoolSize() != dynamicCoreSize || (allowSizesToDiverge && threadPool.getMaximumPoolSize() != dynamicMaximumSize)) {
if (maxTooLow) {
logger.error("Hystrix ThreadPool configuration for : " + metrics.getThreadPoolKey().name() + " is trying to set coreSize = " +
dynamicCoreSize + " and maximumSize = " + configuredMaximumSize + ". Maximum size will be set to " +
dynamicMaximumSize + ", the coreSize value, since it must be equal to or greater than the coreSize value");
}
threadPool.setCorePoolSize(dynamicCoreSize);
threadPool.setMaximumPoolSize(dynamicMaximumSize);
}
threadPool.setKeepAliveTime(properties.keepAliveTimeMinutes().get(), TimeUnit.MINUTES);
}
代码示例来源:origin: com.zaxxer/HikariCP
addConnectionExecutor.setCorePoolSize(Runtime.getRuntime().availableProcessors());
addConnectionExecutor.setCorePoolSize(1);
代码示例来源:origin: igniterealtime/Openfire
( (ThreadPoolExecutor) executorFilter.getExecutor()).setCorePoolSize( ( configuration.getMaxThreadPoolSize() / 4 ) + 1 );
( (ThreadPoolExecutor) executorFilter.getExecutor()).setMaximumPoolSize( ( configuration.getMaxThreadPoolSize() ) );
内容来源于网络,如有侵权,请联系作者删除!