亚洲免费在线视频-亚洲啊v-久久免费精品视频-国产精品va-看片地址-成人在线视频网

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

java 如何根據(jù)內(nèi)存占用情況調(diào)整開線程的數(shù)量?

瀏覽:94日期:2024-02-16 16:27:44

問題描述

問題解答

回答1:

setMaximumPoolSize 是否動(dòng)態(tài)有效看下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} }

標(biāo)簽: java
相關(guān)文章:
主站蜘蛛池模板: 中文字幕在线播放 | 亚洲欧美日韩成人一区在线 | 性国产精品 | 国产日韩欧美在线观看不卡 | 久久精品免费一区二区视 | 91精品国产福利尤物免费 | 国产成人精品日本亚洲语音1 | 精品自拍视频 | 18videosex性欧美69超高清 | 国产一区二区在线看 | 成 人 黄 色 免费播放 | 国产亚洲人成a在线v网站 | 日韩高清成人毛片不卡 | 久久免费在线观看 | 亚洲色吧| 欧美色穴 | 日韩中文字幕免费观看 | 波多野结衣在线观看高清免费资源 | 在线播放日韩 | 久久在视频| 美女黄页网站免费进入 | 国产亚洲精品高清在线 | 亚洲欧美日韩在线观看二区 | 色悠久 | 一区自拍| 亚洲欧美日韩一级特黄在线 | 在线观看免费视频国产 | 日韩a级片 | 国产日产精品_国产精品毛片 | 亚洲第一网色综合久久 | 欧美13一14sexvideo欧 | 久青草免费视频 | 暴操女人| 成人欧美精品一区二区不卡 | 成人毛片1024你懂的 | 亚洲福利视频一区二区三区 | 国产亚洲精品一区二区三区 | 一区二区三区中文 | 日本免费久久 | 99热久久国产这里是精品 | 亚洲成a人在线观看 |