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

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

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

瀏覽:92日期: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
相關文章:
主站蜘蛛池模板: 中文字幕无人区二 | 亚洲综合日韩 | 国产精品黄 | 黄a视频 | 色天使在线视频 | 精品国产乱码久久久久久88av | 日韩hd | 超碰在线看 | 国产91热爆ts人妖系列 | 国产一区二区三区四区 | 亚洲777| 亚洲天堂视频在线 | 黄色大片免费在线观看 | 在线中文字幕视频 | 色综合久久综合 | 又黄又爽又刺激的视频 | 精品少妇一区二区三区免费观 | 天天看天天干 | 国产精品视频免费在线观看 | 91精品久久久久久久久久 | 欧美精品网 | 亚洲精品美女 | 天堂久久久久 | 欧美日韩精品一区 | 亚洲在线一区二区 | 日本少妇中文字幕 | 久婷婷| 欧美日批视频 | 久久久免费观看 | 九九在线观看高清免费 | 日韩精品视频免费在线观看 | 亚洲精品911 | 国产一级免费观看 | 长河落日 | 国产精品自拍小视频 | 日韩免费在线观看视频 | 久久xxxx| 免费毛片网站 | 狠狠久 | 亚洲精品91天天久久人人 | 蜜臀久久99精品久久久久宅男 |