当前位置: 首页>>代码示例>>Java>>正文


Java ThreadPoolExecutor.getMaximumPoolSize方法代码示例

本文整理汇总了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);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:24,代码来源:InternalCountOperation.java

示例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());
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:34,代码来源:ThreadPoolStatusChecker.java

示例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);
        }
    }
}
 
开发者ID:tiglabs,项目名称:jsf-sdk,代码行数:38,代码来源:RegistryCallbackHandler.java

示例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();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:JSR166TestCase.java


注:本文中的java.util.concurrent.ThreadPoolExecutor.getMaximumPoolSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。