国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

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

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

瀏覽:85日期: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亚洲精品成人一区 | 97国产精品欧美一区二区三区 | 欧洲免费无线码一二区 | 久久99精品综合国产首页 | 日韩中文在线 | 国产精品a区 | 国产精品特级毛片一区二区三区 | 日本 亚洲 欧美 | 国产成人a一区二区 | 一本大道香蕉大vr在线吗视频 | 96精品免费视频大全 | 亚洲精品高清国产一久久 | 欧美一区二区三区激情视频 | 免费不卡毛片 | 久久综合九九亚洲一区 | 色视频在线观看免费 | 日本色网址 | 日本在线观看网址 | 欧美性f| 黄网站在线播放视频免费观看 | 精品国产日韩亚洲一区二区 | 欧美一级在线观看 | 手机看片神马午夜 | 国产三级网站在线观看 | 日本一区二区三区高清在线观看 | 亚洲欧美日韩国产综合 | 亚洲自拍中文 | 99爱视频免费高清在线观看 | 国产三级日本三级在线播放 | 日韩午夜 | 理论在线看 | 99精品欧美一区二区三区 | 久久精品在线免费观看 | 欧美成人日韩 | 日本aaaa特级毛片 | 就草草在线观看视频 | 国产亚洲自拍一区 | 加勒比色综合久久久久久久久 | 国产精品成人观看视频国产 | 91久久国产精品 | 无限资源中文免费 |