亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

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

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

瀏覽:66日期: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
相關文章:
主站蜘蛛池模板: 久久久不卡国产精品一区二区 | 免费又黄又爽又猛大片午夜 | 成年人免费黄色 | 亚洲日产综合欧美一区二区 | 日日干夜夜干 | 亚洲一区二区观看 | 一级黄色片一级片 | 成人性视屏 | 国产在线精品一区二区高清不卡 | 国产毛片视频网站 | 欧美一级在线毛片免费观看 | 夜色成人网 | 国内自拍第五一页 | 成人免费视频视频在线不卡 | 2021国产精品自拍 | 亚洲色图第1页 | 免费人成年短视频在线观看免费网站 | 黄色欧美一级片 | 91madou麻豆| 亚洲图片一区二区 | 青青青草网站免费视频在线观看 | 黄色xxx| 婷婷国产在线 | 亚洲欧美日韩中文字幕一区二区三区 | 成人9久久国产精品品 | 亚洲国产精品一区二区三区在线观看 | 国产成人做受免费视频 | 亚洲黄色在线观看视频 | 51精品视频在线播放观看 | 亚洲欧美日韩精品永久在线 | 拍拍拍拍拍拍拍无挡大全免费 | a一级特黄日本大片 s色 | 欧洲一级做a爱在线观看 | 午夜国产高清精品一区免费 | 手机在线观看精品国产片 | freesexvideo性大全 | 欧美肥老妇做爰视频 | 色久激情| 黑人巨大在线 | 欧美日韩国产成人精品 | 久久久一级 |