亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

java 如何根據內存占用情況調整開線程的數量?

瀏覽:60日期:2024-02-16 16:27:44

問題描述

問題解答

回答1:

setMaximumPoolSize 是否動態有效看下jdk源碼不就知道了

/** * Sets the maximum allowed 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. * * @param maximumPoolSize the new maximum * @throws IllegalArgumentException if the new maximum is * less than or equal to zero, or * less than the {@linkplain #getCorePoolSize core pool size} * @see #getMaximumPoolSize */ public void setMaximumPoolSize(int maximumPoolSize) {if (maximumPoolSize <= 0 || maximumPoolSize < corePoolSize) throw new IllegalArgumentException();final ReentrantLock mainLock = this.mainLock;mainLock.lock();try { int extra = this.maximumPoolSize - maximumPoolSize; this.maximumPoolSize = maximumPoolSize; if (extra > 0 && poolSize > maximumPoolSize) {try { Iterator<Worker> it = workers.iterator(); while (it.hasNext() && extra > 0 && poolSize > maximumPoolSize) {it.next().interruptIfIdle();--extra; }} catch (SecurityException ignore) { // Not an error; it is OK if the threads stay live} }} finally { mainLock.unlock();} }

execute方法:

/** * Executes the given task sometime in the future. The task * may execute in a new thread or in an existing pooled thread. * * If the task cannot be submitted for execution, either because this * executor has been shutdown or because its capacity has been reached, * the task is handled by the current <tt>RejectedExecutionHandler</tt>. * * @param command the task to execute * @throws RejectedExecutionException at discretion of * <tt>RejectedExecutionHandler</tt>, if task cannot be accepted * for execution * @throws NullPointerException if command is null */ public void execute(Runnable command) {if (command == null) throw new NullPointerException();if (poolSize >= corePoolSize || !addIfUnderCorePoolSize(command)) { if (runState == RUNNING && workQueue.offer(command)) {if (runState != RUNNING || poolSize == 0) ensureQueuedTaskHandled(command); } else if (!addIfUnderMaximumPoolSize(command))reject(command); // is shutdown or saturated} }

標簽: java
相關文章:
主站蜘蛛池模板: 一区二区在线视频观看 | 国产产一区二区三区久久毛片国语 | 特黄特色的大片观看免费视频 | 超高清欧美videos360 | 中文精品久久久久国产不卡 | 成人免费国产gav视频在线 | 国产精品亚洲第一区在线28石 | 伊人色婷婷 | 日本成人黄色片 | 国产日韩线路一线路二 | 任你躁在线精品视频m3u8 | 日韩不卡免费视频 | 久久久久国产精品免费免费不卡 | 青青操在线视频 | 黄色伊人网 | 尤物精品国产第一福利三区 | 精品视频一区二区三区 | 精品国产一区二区三区成人 | 国产精品91在线播放 | 麻豆成人传媒一区二区 | 久久精品国产免费高清 | 国产自在自线2021 | 亚洲欧美国产高清va在线播放 | 一区二区高清视频在线观看 | 国产精品嫩草影院人体模特 | 性xxxxxxx动漫视频 | 日本欧美中文字幕人在线 | 国产欧美日韩精品a在线观看 | 婷婷五月色综合 | 国产合集福利视频在线视频 | 久草青娱乐 | www.久久草 | 亚洲国产精品免费观看 | 蕾丝视频在线观看www | 午夜精品久久久久久久第一页 | 亚欧成人中文字幕一区 | 国产女人毛片 | 国产日韩在线观看视频网站 | 国产精品1024在线永久免费 | 美国特级a毛片免费网站 | 久久草在线观看 |