色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

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

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

瀏覽:77日期: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美女毛片 | 久久免费手机视频 | 亚洲国产精品日韩在线观看 | 99精品在线免费观看 | 米奇精品一区二区三区在线观看 | 国产在线精品一区二区三区不卡 | 国产乱子精品免费视观看片 | 成 人 免费 网站 | 欧美兽皇video | 毛片免费观看久久欧美 | 一区二区三区久久精品 | 91久久精品国产一区二区 | 男女男免费视频网站国产 | 制服诱惑中文字幕 | 日本护士视频xxxxxwww | 亚洲理论片在线中文字幕 | 免费看欧美成人性色生活片 | 日韩在线精品 | 亚洲精品亚洲人成在线 | 精品视频一区二区三区 | 欧美日韩精品乱国产538 | 国产精品线在线精品 | 草草影| 丝袜紧身裙国产在线播放 | 男女那个视频免费 | 亚洲国产精品免费观看 | 国产亚洲女在线精品 | 亚洲一区二区三区福利在线 | 成年人免费观看视频网站 | 亚洲精品一二三四区 | 男女朋友做爽爽爽免费视频网 | 国内自拍网红在线综合 |