本文整理汇总了Java中java.util.concurrent.ThreadPoolExecutor.getMaximumPoolSize方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadPoolExecutor.getMaximumPoolSize方法的具体用法?Java ThreadPoolExecutor.getMaximumPoolSize怎么用?Java ThreadPoolExecutor.getMaximumPoolSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.ThreadPoolExecutor
的用法示例。
在下文中一共展示了ThreadPoolExecutor.getMaximumPoolSize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: count
import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
@Override
public ListenableFuture<Long> count(Map<String, ? extends Collection<Integer>> indexShardMap,
final WhereClause whereClause) throws IOException, InterruptedException {
List<Callable<Long>> callableList = new ArrayList<>();
for (Map.Entry<String, ? extends Collection<Integer>> entry : indexShardMap.entrySet()) {
final String index = entry.getKey();
for (final Integer shardId : entry.getValue()) {
callableList.add(new Callable<Long>() {
@Override
public Long call() throws Exception {
return count(index, shardId, whereClause);
}
});
}
}
ThreadPoolExecutor executor = (ThreadPoolExecutor) threadPool.executor(ThreadPool.Names.SEARCH);
int corePoolSize = executor.getMaximumPoolSize();
MergePartialCountFunction mergeFunction = new MergePartialCountFunction();
ListenableFuture<List<Long>> listListenableFuture = ThreadPools.runWithAvailableThreads(
executor, corePoolSize, callableList, mergeFunction);
return Futures.transform(listListenableFuture, mergeFunction);
}
示例2: check
import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
public Status check() {
DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
Map<String, Object> executors = dataStore.get(Constants.EXECUTOR_SERVICE_COMPONENT_KEY);
StringBuilder msg = new StringBuilder();
Status.Level level = Status.Level.OK;
for(Map.Entry<String, Object> entry : executors.entrySet()) {
String port = entry.getKey();
ExecutorService executor = (ExecutorService) entry.getValue();
if (executor != null && executor instanceof ThreadPoolExecutor) {
ThreadPoolExecutor tp = (ThreadPoolExecutor) executor;
boolean ok = tp.getActiveCount() < tp.getMaximumPoolSize() - 1;
Status.Level lvl = Status.Level.OK;
if(!ok) {
level = Status.Level.WARN;
lvl = Status.Level.WARN;
}
if(msg.length() > 0) {
msg.append(";");
}
msg.append("Pool status:" + lvl
+ ", max:" + tp.getMaximumPoolSize()
+ ", core:" + tp.getCorePoolSize()
+ ", largest:" + tp.getLargestPoolSize()
+ ", active:" + tp.getActiveCount()
+ ", task:" + tp.getTaskCount()
+ ", service port: " + port);
}
}
return msg.length() == 0 ? new Status(Status.Level.UNKNOWN) : new Status(level, msg.toString());
}
示例3: 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);
}
}
}
示例4: saturatedSize
import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
* Returns maximum number of tasks that can be submitted to given
* pool (with bounded queue) before saturation (when submission
* throws RejectedExecutionException).
*/
static final int saturatedSize(ThreadPoolExecutor pool) {
BlockingQueue<Runnable> q = pool.getQueue();
return pool.getMaximumPoolSize() + q.size() + q.remainingCapacity();
}