午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

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

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

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

問題描述

問題解答

回答1:

setMaximumPoolSize 是否動態(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)文章:
主站蜘蛛池模板: 激情高潮到大叫狂喷水 | 欧美国产免费 | 国产精品免费一区二区 | 天天躁日日躁狠狠躁av麻豆男男 | 伊人网综合网 | 伊人久久一区二区 | 久久99国产精品视频 | 99色在线观看 | 亚洲国产精选 | 欧美在线网址 | 五月在线| 欧美天堂在线观看 | 中文字幕日本 | 欧美网站在线观看 | 欧美日韩在线视频免费播放 | 99国产视频 | 日韩男人天堂 | 一区二区三区在线观看 | 伊人久久爱 | 在线中文字日产幕 | 99亚洲欲妇 | 一级特黄特色的免费大片视频 | 99re在线| 欧美亚色 | 69精品久久久久久 | wwwxxx日韩| 久久国产精品久久久 | 四季av一区二区凹凸精品 | 一区二区免费在线观看视频 | 91操操操| 天天干在线播放 | 一个色在线视频 | 欧美精品网站 | 亚洲精品久久久久久久久 | 亚洲欧美激情精品一区二区 | 中国毛片网站 | 福利网站在线观看 | 五月婷婷丁香在线 | 天堂岛av | 中文字幕在线资源 | 亚洲图片一区 |