av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

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

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

瀏覽:78日期: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
相關文章:
主站蜘蛛池模板: 成人在线免费电影 | 欧美久久久久久 | 高清国产一区二区 | 91性高湖久久久久久久久_久久99 | 在线国产欧美 | 欧美三级在线 | 成人国产精品入口免费视频 | 久久久久久高潮国产精品视 | 久久精品91久久久久久再现 | 国产精品久久九九 | 精久久久久 | aaa一区 | 99伊人网| 精久久久| 亚洲欧美中文日韩在线v日本 | 欧美激情一区二区三区 | 中文字幕亚洲视频 | 久久人人爽人人爽人人片av免费 | 亚洲视频免费 | 国产成人精品久久久 | 日本大香伊一区二区三区 | 成人精品国产一区二区4080 | 欧美日韩精品一区二区三区蜜桃 | 男女污污动态图 | 日韩免费| 欧美aaaaa | 亚洲一区二区三区在线播放 | 九九久久99 | 日韩欧美在线视频 | 91精品久久久久久久久 | 国产精品欧美一区二区 | 中国一级特黄真人毛片免费观看 | 91 视频网站 | 亚洲综合网站 | 免费成人av | 国产精品91视频 | 国产在线麻豆精品入口 | 超碰国产在线 | 国产在线观看一区二区三区 | 99久久久久久久 | 国产精品福利视频 |