當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。