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玖玖| www.久久久.com | 日本中文字幕在线视频 | 日本精品久久久一区二区三区 | 免费看a| 日韩一区二区三区四区五区 | 香蕉久久a毛片 | 九色在线观看 | 狠狠干天天干 | 久热国产在线 | 国产精品日产欧美久久久久 | 日本不卡免费新一二三区 | 久久久久国产精品午夜一区 | 九九久久免费视频 | 久久夜夜 | 色婷婷亚洲一区二区三区 | 在线播放国产视频 | 亚洲一区二区久久久 | 欧美日韩一区二区视频在线观看 | 九九热在线视频 | 日韩一区二区三区四区五区六区 | 国产精品a久久久久 | 日韩电影中文字幕 | 国产99精品 | 精品国产精品 | 国产精品一区2区 | 欧美精品在线看 | 中文字幕在线中文 | 色婷婷国产精品 | 久久精品亚洲精品国产欧美kt∨ | 狠狠干天天干 | 日日夜夜天天综合 | 色综合天天综合网国产成人网 | 美日韩免费 | 国产美女精品视频 | 理论片87福利理论电影 | 99精品国产一区二区三区 | 九九综合| 日韩av电影院 |