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

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

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

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

問(wèn)題描述

問(wèn)題解答

回答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)文章:
主站蜘蛛池模板: 日本乱人伦片中文字幕三区 | 99国产成人高清在线视频 | 九九99精品 | 美女被免费网站在线软件 | 日本大黄网站 | 无码免费一区二区三区免费播放 | 国产成人精品视频播放 | 美国一级毛片片aaa 美国一级毛片片aa成人 | 久久综合九九亚洲一区 | 男女性男女刺激大片免费观看 | 在线 中文字幕 日韩 欧美 | 中文字幕一区二区三区久久网站 | 亚洲高清不卡 | 日本特黄特色大片免费视频网站 | 国产午夜精品久久久久免费视 | 日本三级欧美三级人妇英文 | 国产亚洲精品美女一区二区 | 欧美国产成人精品一区二区三区 | 国产亚洲高清不卡在线观看 | 538prom精品视频在放免费 | 91成人免费观看 | 亚洲国产欧美视频 | 一级做a爰全过程免费视频毛片 | 美女把张开腿男生猛戳免费视频 | 国产亚洲精品成人婷婷久久小说 | 韩国一级做a爰片性色毛片 韩国一区在线 | 午夜不卡视频 | 欧美性生交大片免费看 | 国产男女免费视频 | wwww.黄| 日日干夜夜爽 | 色综合久久久久久888 | 能直接看的一级欧美毛片 | 黄色三级日韩 | 91探花福利精品国产自产在线 | 毛片日韩 | 免费一级a毛片在线播放视 免费一级α片在线观看 | 日日碰碰 | 怡红院日本一道日本久久 | 久久青草网站 | 国产一级一级一级成人毛片 |