国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

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

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

瀏覽:85日期: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
相關文章:
主站蜘蛛池模板: 国产中文在线视频 | 成人免费在线视频 | 男人的天堂精品国产一区 | 经典三级久久 | 九九精彩视频在线观看视频 | xxxxxhd亚洲日本hd | 国产精品高清全国免费观看 | 国产一区二区在线观看免费 | 国产综合精品久久亚洲 | 男女晚上爱爱的视频在线观看 | 成人一级片在线观看 | 成人亚洲欧美综合 | 欧美日韩一区二区三区视频在线观看 | 国产精品青草久久福利不卡 | 在线播放 亚洲 | 国产系列在线 | 九九99 | 狠狠色狠狠色综合久久第一次 | 高清午夜看片a福利在线观看琪琪 | 久久久一级 | 国产三级在线播放线 | 91久久夜色精品国产网站 | 午夜dj视频完整社区 | 精品久久香蕉国产线看观看亚洲 | 欧美国产日韩久久久 | 99国产高清久久久久久网站 | 日韩欧美中文字幕在线观看 | 99精品久久99久久久久久 | 综合免费视频 | 久久久久视频精品网 | 亚洲一二区| 欧美视频一区二区三区精品 | 亚洲精品一区二区三区在线观看 | 特级a欧美做爰片毛片 | 日韩性视频网站 | 精品久久久久久久久久久 | 欧美一级色 | 亚洲天堂视频网 | 国产欧美一区二区三区视频在线观看 | 91精品国产综合久久久久久 | 成人精品第一区二区三区 |